我试图使用GPG命令解密我的文件:
FileInfo info = new FileInfo(@"C:\Users\***\Desktop\files\file.pgp");
string decryptedFileName = info.FullName.Substring(0, info.FullName.LastIndexOf('.')) + "Dec.TXT";
string encryptedFileName = info.FullName;
string password = "pass";
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:\Program Files (x86)\GNU\GnuPG";
System.Diagnostics.Process process = System.Diagnostics.Process.Start(psi);
//string sCommandLine = @"echo " + password + "|gpg.exe --passphrase-fd 0 --batch --verbose --yes --output " + decryptedFileName + @" --decrypt """ + encryptedFileName;
string sCommandLine = @"gpg --output " + decryptedFileName + @" --decrypt """ + encryptedFileName;
process.StandardInput.WriteLine(sCommandLine);
process.StandardInput.Flush();
process.StandardInput.Close();
process.WaitForExit();
string result = process.StandardOutput.ReadToEnd();
string error = process.StandardError.ReadToEnd();
process.Close(); 不幸的是,我得到了以下错误:“使用: gpg选项\r\n”
发布于 2014-08-04 11:48:16
错误消息指示传递的参数是错误的。这两个字符串中要么是未设置的,要么是特殊字符转义的问题。
转储sCommandLine (或者在那里添加调试器断点),这两个文件名中可能有一个是空的,或者是严重转义的。这将很容易地帮助您找到导致问题的变量。
您还可以考虑使用本机OpenPGP库,比如BouncyCastle,而不是从C#调用GnuPG二进制文件。
https://stackoverflow.com/questions/25117178
复制相似问题