Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 用PGP和C解密文件#_C#_Pgp_Encryption_Openpgp - Fatal编程技术网

C# 用PGP和C解密文件#

C# 用PGP和C解密文件#,c#,pgp,encryption,openpgp,C#,Pgp,Encryption,Openpgp,我的问题是,当命令行运行时,它不会在我的解密文本文件中添加任何内容。我在decrypt.txt文件中添加了文本,以查看它是否会写入,因为文本会被删除 System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("cmd.exe"); psi.CreateNoWindow = true; psi.UseShellExecute =

我的问题是,当命令行运行时,它不会在我的解密文本文件中添加任何内容。我在decrypt.txt文件中添加了文本,以查看它是否会写入,因为文本会被删除

        System.Diagnostics.ProcessStartInfo psi =
        new System.Diagnostics.ProcessStartInfo("cmd.exe");
        psi.CreateNoWindow = true;
        psi.UseShellExecute = false;
        psi.RedirectStandardInput = true;
        psi.RedirectStandardOutput = true;
        psi.RedirectStandardError = true;
        psi.WorkingDirectory = "c:\\";

        System.Diagnostics.Process process = System.Diagnostics.Process.Start(psi);
        string sCommandLine = "echo femme toxin sorghum| gpg.exe --batch --passphrase-fd 0 --decrypt E:\\entemp.txt > E:\\detemp.txt";
        process.StandardInput.WriteLine(sCommandLine);
        process.StandardInput.Flush();
        process.StandardInput.Close();
        process.WaitForExit();
        process.Close();

最近我做了很多gpg.exe的东西

我认为您正在将gpg命令标准重定向到您的文件

你可能想要更像这样的东西

echo password123 | gpg.exe--是--批处理--密码短语fd 0--解密--输出c:\file.txt c:\file.gpg

您也可以在进程中直接调用gpg.exe,而不是调用cmd然后传递命令…如果这样做,您将禁用“echo”内容并添加
--是。。。c:\file.gpg
等,将其添加到arguments属性。然后…您的第一个输入将类似于
gpgProc.standardinput.writeline(密码123)

此方法还使您能够获取标准错误输出,并直接处理gpg.exe的退出代码,而不是cmd.exe退出代码等


也许这会有帮助…

这表面上与C#有关,您请求pgp的帮助,但使用gpg。。。实际上这是一个gpg问题,所以超级用户可能更合适。