使用 C# 命令行 GPG 解密 - 密码?

发布于 2024-09-30 06:49:21 字数 929 浏览 0 评论 0原文

我正在使用命令行来加密我发送的文件,但我正在尝试找出如何使用相同的方法来解密它们。如果我运行该命令,系统会提示输入密码,但我没有看到使用命令行传递密码的方法。以下是我加密文件的方法:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

冬天的雪花 2024-10-07 06:49:21

属性 Process.StandardInput 应该给你一个StreamWriter 可用于在标准输入上提供密码。

The property Process.StandardInput should give you a StreamWriter that you can use to provide the passphrase on standard input.

眼藏柔 2024-10-07 06:49:21

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.

南巷近海 2024-10-07 06:49:21

使用 --passphrase-fd 0 让 GPG 从 stdin 获取密码,然后使用管道将其传递。

echo 123456| gpg --passphrase-fd 0 -e -u [email protected] -r [email protected] C:\file.csc

gpg --passphrase-fd 0 -e -u [email protected] -r [email protected] --passphrase-fd 2 file.csc < password.file

确保您不会以某种方式在标准输入上传递任何额外的空格,因为 GPG 不能很好地处理这些空格。

我不确定如何在 .NET 上的标准输入上传递某些内容,因此您必须填补那里的空白。

Use --passphrase-fd 0 to get GPG to take the passphrase from stdin and then pass it in using a pipe.

echo 123456| gpg --passphrase-fd 0 -e -u [email protected] -r [email protected] C:\file.csc

or

gpg --passphrase-fd 0 -e -u [email protected] -r [email protected] --passphrase-fd 2 file.csc < password.file

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文