加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – GnuPG加密不适用于进程错误代码2

发布时间:2020-12-15 22:30:34 所属栏目:百科 来源:网络整理
导读:我有下面的代码,当这个加密代码通过命令提示符调用时工作正常(创建加密文件),并且当它在控制台应用程序中时,它不起作用. var destFilePath = @"D:test.gpg";var recipient = "test@test.com";var sourceFilePath = @"D:test.txt";var proc = new Process {
我有下面的代码,当这个加密代码通过命令提示符调用时工作正常(创建加密文件),并且当它在控制台应用程序中时,它不起作用.

var destFilePath = @"D:test.gpg";
var recipient = "test@test.com";
var sourceFilePath = @"D:test.txt";
var proc = new Process
           {
                StartInfo = new ProcessStartInfo
                {
                    FileName = "cmd.exe",Arguments = string.Format("gpg2 --output {0} --encrypt --recipient {1} {2}",destFilePath,recipient,sourceFilePath),UseShellExecute = false,RedirectStandardError = true,RedirectStandardInput = true,RedirectStandardOutput = true,CreateNoWindow = true,WorkingDirectory = @"C:Program Files (x86)GNUGnuPG"
                }
            };

            proc.Start();
            proc.WaitForExit();
            int rc = proc.ExitCode;
            proc.Close();
            Console.WriteLine(rc.ToString());
            Console.ReadKey();

这是在ExitCode中返回错误代码2

任何想法都会有帮助!

解决方法

从 GPG Error Code 2:

GPG is asking whether you want to continue on with the encryption
using an unsigned key. Since no user can input Y it produces an error.

To fix this put the following switches

--yes and --always-trust

我使用GPG已经有一段时间了但是参数的顺序通常并不重要,只要它们被命名

这会给你这样的东西

FileName = "gpg2.exe",Arguments = $"--output {destFilePath} --encrypt --yes --always-trust --recipient {recipient} {sourceFilePath}",

注意:这是C#6格式,稍微容易阅读

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读