PGP使用GnuPG从C#加密

问题描述 投票:3回答:3

我正在尝试用C#加密传入的文档,我正在使用GnuPG和输入重定向。我需要在一个步骤中使用-se(签名和加密),这需要输入密码。但由于某种原因,输入重定向不起作用。感谢您的帮助。控制正在进行其他阻止。我不确定是否有死锁或子进程(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();
}

`

c# encryption gnupg pgp
3个回答
1
投票

您可以做的第一件事是删除重定向并自己查看控制台,以便了解gnupg在做什么/正在等待什么。接下来,尝试将新行字符(\ n或0x13或0x130x10,尝试所有变体)添加到密码的末尾 - 当您键入内容时,按Enter键传递它,您也必须在此处执行相同的操作。最后,您可以使用OpenPGPBlackbox在没有外部应用程序的情况下执行操作。


1
投票

尝试将--passphrase-fd 0添加到GnuPG命令行,以指示它从标准输入中读取密码。


0
投票

当我不得不执行一些解密时,我遇到了同样的问题。我最后做的是像这样管道密码短语。

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

它似乎运作得相当好。

© www.soinside.com 2019 - 2024. All rights reserved.