【发布时间】:2013-03-25 21:09:35
【问题描述】:
我正在尝试编写一个控制台应用程序,该应用程序将根据请求解密 gpg 签名。一切都很好,除了提示输入我的 GPG 密码的部分。如何在没有密码对话框的情况下从命令行调用gpg --decrypt?
到目前为止,这是我的代码:
var startInfo = new ProcessStartInfo("gpg.exe");
startInfo.Arguments = "--decrypt"; //this is where I want to insert "--passphrase MyFakePassword"
startInfo.CreateNoWindow = true;
startInfo.UseShellExecute = false;
startInfo.RedirectStandardInput = true;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.WorkingDirectory = @"C:\Program Files (x86)\GNU\GnuPG";
var proc = Process.Start(startInfo);
var sCommandLine = stringData + "\n"+(char)26+"\n"; //stringData is the encrypted string
proc.StandardInput.WriteLine(sCommandLine);
proc.StandardInput.Flush();
proc.StandardInput.Close();
var result = proc.StandardOutput.ReadToEnd();
我尝试在第一行输入密码时使用--passphrase MyFakePassword、--passphrase-fd MyFakePassword 甚至--passphrase-fd 0。如果可能的话,我想避免将我的密码放在运行此代码的机器上的 txt 文件中。
提前感谢您的帮助。
【问题讨论】: