I am trying to write a console application that will decrypt the gpg signature upon request. Everything will be fine, EXCEPT for the part where it asks for my GPG password. How can I call gpg --decrypt
from the command line without a password dialog?
Here is my code:
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();
I tried using --passphrase MyFakePassword
, --passphrase-fd MyFakePassword
and even --passphrase-fd 0
with my password in the first line of input. I would like not to put my password in a txt file on a machine that runs this code, if at all possible.
Thanks in advance for your help.
source share