PGP Encrypt from C# using GnuPG

Posted by Kishore on Stack Overflow See other posts from Stack Overflow or by Kishore
Published on 2010-06-15T03:28:07Z Indexed on 2010/06/15 3:32 UTC
Read the original article Hit count: 601

Filed under:
|
|

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();
}

`

© Stack Overflow or respective owner

Related posts about c#

Related posts about encryption