tags:

views:

47

answers:

2

Hello All, I'm trying to encrypt a incoming document in C#, and I'm using GnuPG with input redirection. I need to use -se(sign and encrypt) in a single step, which requires entering passphrase. But for some reason, input redirection is not working. Appreciate your help. Control is going to else block. I'm not sure if there is deadlock or child process(gpg.exe) waiting for the input.

pgpproc = new Process();
pgpproc.StartInfo.FileName = exeFilePath;
pgpproc.StartInfo.RedirectStandardOutput = false;
pgpproc.StartInfo.RedirectStandardInput = true;
pgpproc.StartInfo.UseShellExecute = false;
pgpproc.StartInfo.Arguments = "-a  -o C:\PGPStaging\output.pgp -se -r recipientID C:\PGPStaging\input.txt";
pgpproc.StartInfo.CreateNoWindow = true;
pgpproc.Start();
StreamWriter myStreamWriter = pgpproc.StandardInput;
myStreamWriter.Write("*****");
myStreamWriter.Close();

if (pgpproc.WaitForExit(waittime))
{
  //success
}
else
{
  //failure
  pgpproc.Kill();
  pgpproc.WaitForExit();
}

`

+1  A: 

The first thing you can do is remove redirection and see the console yourself in order to get to know, what gnupg is doing / waiting. Next, try adding new-line character (\n or 0x13 or 0x130x10, try all variants) to the end of the password - when you type something, you press Enter to pass it, and you must do the same here as well. Finally, you can use OpenPGPBlackbox to perform the operation without external applications.

Eugene Mayevski 'EldoS Corp
+1  A: 

Try adding --passphrase-fd 0 to the GnuPG command line to instruct it to read password from the standard input.

rkhayrov