有没有办法在脚本中嵌入GPG公钥而不将其添加到密钥环中?


9

我有一个脚本,基本上需要执行以下操作:

#!/bin/bash 

GPG_PUBLIC_KEY=<<EOF
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.12 (GNU/Linux)
...
-----END PGP PUBLIC KEY BLOCK-----
EOF

gpg --encrypt --with-public-key "$GPG_PUBLIC_KEY" myfile.txt

有没有一种方法,而不必先将GPG密钥导入密钥环?


Answers:


6

如果您根本不想使用用户的密钥环,请将GPG指向一个临时密钥环。

tmp=
trap 'rm -rf "$tmp"' EXIT INT TERM HUP
tmp=$(mktemp -d)
export GNUPGHOME="$tmp"
gpg --import <<EOF

EOF
gpg -e -r  myfile.txt

如果还要使用用户的密钥环,请GNUPGHOME仅在import命令期间进行设置,然后传递--keyring "$tmp/pubring.gpg"给第二个gpg命令。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.