【问题标题】:How can we avoid the gnupg passphrase prompt in C# for Windows?我们如何避免 C# for Windows 中的 gnupg 密码提示?
【发布时间】:2018-09-16 00:02:44
【问题描述】:

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

我卡住了,因为我的 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();

【问题讨论】:

    标签: c# asp.net encryption gnupg passphrase


    【解决方案1】:

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

    使用命令文本作为

    gpg --output "decrypted_file_name" --batch --passphrase "passphrase_goes_here" --decrypt "encrypted_file_name"
    

    【讨论】:

      最近更新 更多