PGP Encrypt from C # using GnuPG

I am trying to encrypt an incoming document in C # and I am using GnuPG with input redirection. I need to use -se (sign and encrypt) in one step, which requires a passphrase. But for some reason input redirection does not work. I appreciate your help. Control will block. I'm not sure that pending input will be deadlock or child process (gpg.exe).

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

`

+3
source share
3 answers

, , , , / gnupg. (\n 0x13 0x130x10, ) . -, Enter, , . , OpenPGPBlackbox .

+1

--passphrase-fd 0 GnuPG, .

+1

, . , , - .

    procStartInfo.Arguments = @"/c echo " + passphrase + @"| c:\gnupg\gpg --passphrase-fd --     decrypt --output " + "\"" + fileLocationToDecryptTo + "\"" + " \"" + fileLocationToDecryptFrom     + "\"";

, .

0

Source: https://habr.com/ru/post/1750039/


All Articles