长话短说,我的问题是:如何在加密/解密文件时强制GnuPG使用哪个私钥/公钥?
我有一个应用程序必须加密文件,然后再将它们发送到S3.
用户可以使用他们的浏览器从我的网站下载他们的文件,在这种情况下,我必须首先解密文件,然后再提供.
客户端(delphi 2010):我很可能会选择OpenPGPBlackbox
服务器端(PHP 5),我需要弄清楚如何使用非交互式命令加密/解密文件.
我在我的服务器上安装了GnuPG,试过这段代码:
clear_file='/full/path/my-file.zip'
encrypted_file='/full/path/my-file.zip.pgp'
# Encrypt file
/usr/bin/gpg2 --encrypt "$clear_file"
# Decrypt file
/usr/bin/gpg2 --decrypt "$encrypted_file"
Run Code Online (Sandbox Code Playgroud)
但似乎我无法在命令行中指定使用哪些密钥.
每个用户都有自己的公钥/私钥,因此我需要能够指定用于加密/解密相关文件的密钥.
我的问题是:如何在加密/解密文件时强制GnuPG使用哪个私钥/公钥?
您正在寻找的选项是:
--default-key $name$
Use $name$ as the default key to sign with. If this option is not used, the default key is
the first key found in the secret keyring. Note that -u or --local-user overrides this
option.
--local-user $name$
-u Use $name$ as the key to sign with. Note that this option overrides --default-key.
Run Code Online (Sandbox Code Playgroud)
或者可能:
--recipient $name$
-r Encrypt for user id $name$. If this option or --hidden-recipient is not specified,
GnuPG asks for the user-id unless --default-recipient is given.
--default-recipient $name$
Use $name$ as default recipient if option --recipient is not used and don't ask if
this is a valid one. $name$ must be non-empty.
Run Code Online (Sandbox Code Playgroud)
这些可用于指定谁是预期收件人,例如,用于签名/加密的公钥.解密文件时,GnuPG会自动选择当前密钥环中存在的正确密钥--keyring,如果存在多个密钥,则可以选择该密钥.GnuPG还可以配置为从密钥服务器获取必要的密钥(如果它们在那里可用).
您可能也对选项感兴趣,该选项--batch确保在执行期间不会询问任何交互式问题.
我建议你阅读GnuPG手册页.有很多选项可能偶尔会有用.
| 归档时间: |
|
| 查看次数: |
13858 次 |
| 最近记录: |