0

我正在尝试将我们的旧代码从 gnupg1.x 升级到 gnupg2.2.4。这是在 Windows 机器上,我为 windows gnupg-w32-2.2.4_20171220.exe 安装了 gnupg。

我被卡住了,因为我的 C# 应用程序不断提示我输入密码和超时,并且无法解密文件并且进程失败。一直以来,这个应用程序在没有太多用户干预的情况下运行,我们仍然希望它这样。有没有办法避免每次 gnupg 尝试解密文件时出现的密码提示?这是我当前的代码基于来自该社区的其他反馈的样子,但我无法弄清楚我做错了什么。它当前创建一个空文件并且没有内容。虽然我的加密文件确实有内容。我还阅读了有关使用 gpg --preset-passphrase 的信息,但我的发布团队不鼓励我使用它。你能帮忙吗?

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

1 回答 1

0

我也面临同样的问题。它在 GUI 中反复询问密码。所以经过多次猎头找到了解决方案。

使用命令文本作为

gpg --output "decrypted_file_name" --batch --passphrase "passphrase_goes_here" --decrypt "encrypted_file_name"
于 2018-06-05T07:11:22.760 回答