使用 C# 命令行 GPG 解密 - 密码?
我正在使用命令行来加密我发送的文件,但我正在尝试找出如何使用相同的方法来解密它们。如果我运行该命令,系统会提示输入密码,但我没有看到使用命令行传递密码的方法。以下是我加密文件的方法:
var proc = new Process();
proc.EnableRaisingEvents = false;
proc.StartInfo.WorkingDirectory = "C:\\";
proc.StartInfo.FileName = @"C:\Progra~1\GNU\GnuPG\gpg.exe";
proc.StartInfo.Arguments = @"-e -u ""[email protected]"" -r ""[email protected]"" ""C:\file.csc""";
proc.Start();
proc.WaitForExit();
** 这是用于我的解决方案的有用链接: http://social. msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/38c21304-fc7a-42cc-a5fb-dcb6da7f6411/
I'm using the command line to encrypt files that I am sending out but I am trying to figure out how to use the same method to decrypt them. If I run the command it get prompted for the passphrase, but I don't see a way to pass in the passphrase using the command line. Here is how I am encrypting the file:
var proc = new Process();
proc.EnableRaisingEvents = false;
proc.StartInfo.WorkingDirectory = "C:\\";
proc.StartInfo.FileName = @"C:\Progra~1\GNU\GnuPG\gpg.exe";
proc.StartInfo.Arguments = @"-e -u ""[email protected]"" -r ""[email protected]"" ""C:\file.csc""";
proc.Start();
proc.WaitForExit();
** Here is a useful link that was used for my solution:
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/38c21304-fc7a-42cc-a5fb-dcb6da7f6411/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
属性 Process.StandardInput 应该给你一个StreamWriter 可用于在标准输入上提供密码。
The property Process.StandardInput should give you a StreamWriter that you can use to provide the passphrase on standard input.
Linux 上的 GPG 有 --passphrase-fd N,其中 N 是 int。如果 N == 0,则从标准输入读取密码。
不确定这是否同样适用于 Windows,但可能值得一试。
GPG on Linux has --passphrase-fd N, where N is int. If N == 0, the passphrase is read from standard input.
Not sure if the same applies on Windows but might be worth checking out.
使用
--passphrase-fd 0
让 GPG 从 stdin 获取密码,然后使用管道将其传递。或
确保您不会以某种方式在标准输入上传递任何额外的空格,因为 GPG 不能很好地处理这些空格。
我不确定如何在 .NET 上的标准输入上传递某些内容,因此您必须填补那里的空白。
Use
--passphrase-fd 0
to get GPG to take the passphrase from stdin and then pass it in using a pipe.or
Make sure you don't pass any extra spaces on stdin somehow as GPG doesn't handle those well.
I'm not sure how you can pass something on stdin on .NET, so you'll have to fill the gap there.