我正在尝试编写一个控制台应用程序,它将根据请求解密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();
Run Code Online (Sandbox Code Playgroud)
我已尝试使用--passphrase MyFakePassword,--passphrase-fd MyFakePassword甚至--passphrase-fd 0在第一行输入时使用我的密码.如果可能的话,我想避免将我的密码放在运行此代码的机器上的txt文件中.
在此先感谢您的帮助.