【发布时间】:2014-08-04 11:03:43
【问题描述】:
我尝试使用 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();
不幸的是,我收到以下错误:“usage: gpg [options] [filename]\r\n” 知道有什么问题吗?
【问题讨论】:
-
转储
sCommandLine,可能两个文件名之一为空或严重转义。 -
是的,你是对的。我将文件名更改为: string decryptedFileName = "file_enc.txt"; string encryptedFileName = "file.pgp";现在它可以正常工作了,谢谢!
-
我再次发布了评论作为答案(显然是),并提供了更多详细信息,因此您可以接受。
标签: c# encryption cmd gnupg