我想在decrypt
没有任何用户干预的情况下使用GnuPG的命令。脚本的--passphrase-fd
参数似乎正是我所需要的。但我不知道它是如何工作的-尚未找到示例。
在Windows和UNIX环境下,谁能给我这样的命令的示例?
(仅供参考,我正在使用GnuPG 2)。
已经谢谢你了:)
为了--passphrase-fd
在GnuPG v2中使用gpg选项,您必须指定--batch
参数。我将首先解释其--passphrase-fd
工作原理,然后介绍示例。
--passphrase-fd
告诉GnuPG期望密码短语来自哪个文件描述符(-fd)。标准文件描述符为STDIN(0),STDOUT(1)和STDERR(2)。对于此问题,您通常只关心STDIN(0)。
您没有指定密码的来源,因此我将以多种方式演示STDIN(标准输入)的用法。
--passphrase-fd 0
告诉GnuPG从输入到当前shell的密码中获取密码;因此,例如,如果您希望GnuPG在控制台输入的下一行中获取密码数据,则命令和输出将如下所示:
gpg2 --batch --passphrase-fd 0 --armor --decrypt /path/to/encrypted_file.pgp
<next line of input is passphrase followed by hitting enter>
gpg: encrypted with 1024-bit RSA key, ID EC18C175, created 2013-10-26
"testkey4321 (4321) <[email protected]>"
this is a test... this is only a test...
在上面的示例中,密码通过文件描述符0(STDIN)提供-我们通过在shell当前的标准输入中输入密码来提供密码。
在下一个示例中,我们将告诉GnuPG从当前shell的输入中检索密码短语,该密码实际上是另一个命令的输出(在这种情况下,echo只是“回声”您告诉的内容):
echo "mypassphrase" | gpg2 --batch --passphrase-fd 0 --armor --decrypt /path/to/encrypted_file.pgp
gpg: encrypted with 1024-bit RSA key, ID EC18C175, created 2013-10-26
"testkey4321 (4321) <[email protected]>"
this is a test... this is only a test...
将包含密码短语的文件的内容转储到STDIN的另一个示例-
cat /path/to/file_with_passphrase | gpg2 --batch --passphrase-fd 0 --armor --decrypt /path/to/encrypted_file.pgp
gpg: encrypted with 1024-bit RSA key, ID EC18C175, created 2013-10-26
"testkey4321 (4321) <[email protected]>"
this is a test... this is only a test...
总之,--passphrase-fd
只是告诉GnuPG您想通过标准文件描述符为它提供必要的密码。GnuPG v2和GnuPG之间的区别仅仅是--batch
参数。
上面的示例在Windows和* nix环境中应该工作相同,唯一的区别是在Windows中-根据您的配置和版本-您必须将其替换cat
为type
才能将文件内容转储到STDIN。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句