I am trying to upgrade our legacy code from gnupg1.x to gnupg2.2.4. This is on Windows machine and I installed gnupg for windows gnupg-w32-2.2.4_20171220.exe.
I am stuck as my C# application keeps prompting me to enter the passphrase and time outs and is not able to decrypt the file and the process fails. All this time this application has run without much user intervention and we still want it that way. Is there anyway to avoid the passphrase prompt that comes up every time gnupg tries to decrypt a file? This is what my current code looks like based on other feedback from this community but I cant figure out what I am doing wrong. It currently creates an empty file and there is no content. Although my encrypted file does have content in it. I also read about using gpg --preset-passphrase but my release team is discouraging me from using that. Can you please help.
string _commandlineParams = "--home " + gnuHomedir + " --default-key " + "myRealIDKey" + " --batch" + " --passphrase-fd 0" + " --decrypt " + pathAndfile;
string vgpg = "echo " + gphrase + "|gpg ";
string gpgExecutable = Path.Combine(gnuBinDirectory, "gpg");
ProcessStartInfo pInfo = new ProcessStartInfo(gpgExecutable, _commandlineParams);
pInfo.WorkingDirectory = _gnuBinDirectory;
pInfo.CreateNoWindow = true;
pInfo.UseShellExecute = false;
pInfo.RedirectStandardInput = true;
pInfo.RedirectStandardOutput = true;
pInfo.RedirectStandardError = true;
string sCommandLine = vgpg + " " + _commandlineParams;
if (sCommandLine != null)
{
_processObject.StandardInput.WriteLine(sCommandLine);
//_processObject.StandardInput.WriteLine(gphrase); -- tried this too but didnt work
_processObject.StandardInput.Flush();
}
_processObject.StandardInput.Close();