使用 PGP 和 C# 解密文件
我的问题是当命令行运行时它不会在我的解密文本文件中添加任何内容。我向解密.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();
My problem is when the command line runs it doesn't add anything in my decrypt text file. I added text to the decrypt.txt file to see if it writes to it and it does because the text gets deleted.
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();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最近做了很多 gpg.exe 的事情...
我认为您正在将 gpg 命令标准重定向到您的文件...
您可能想要更多类似这样的东西
echo password123|gpg.exe -- yes --batch --passphrase-fd 0 --decrypt --output c:\file.txt c:\file.gpg
您也可以直接在进程中调用 gpg.exe,而不是调用 cmd 然后传递一个命令...如果你这样做不过,您将取消“echo”内容并将
--yes ... c:\file.gpg
等添加到参数属性中。那么...您的第一个输入将类似于 gpgProc.standardinput.writeline(password123);此方法还使您能够直接获取标准错误输出并处理 gpg.exe 的退出代码,而不是使用 cmd .exe 退出代码等
也许会有所帮助......
i've been doing a lot of gpg.exe stuff lately...
i think you are redirecting your gpg command standard out to your file...
you may want something more like this
echo password123|gpg.exe --yes --batch --passphrase-fd 0 --decrypt --output c:\file.txt c:\file.gpg
you could also call gpg.exe directly in your process instead of calling cmd and then passing a command...if you do that though, you'll nix the "echo" stuff and add
--yes ... c:\file.gpg
and so on to an arguments property. then...your first input will be likegpgProc.standardinput.writeline(password123);
this method also gives you the ability to get standard error output and process exit codes for gpg.exe directly instead of cmd.exe exit code, etc.
perhaps that will help...