我想将导入的公钥 ( gpg --import
) 分组来组织它们。
例如,我有一堆我想保留很长时间的公钥,而不是其他我需要使用一次或两次并最终删除它们的密钥(没有组,我必须手动检查所有密钥)。
答案1
--keyring
使用和弄清楚了--no-default-keyring
。
添加了一些功能以.zshrc
使事情更加高效(在 macOS 上,默认密钥环称为pubring.gpg
)。
# Search keys.openpgp.org
function search-keys() {
if [ -z "$1" ]; then
printf "%s\n" "Usage: search-keys [keyring] id"
return 1
fi
if [ -z "$2" ]; then
2=$1
1=pubring.gpg
fi
if [ $1 != "pubring.gpg" ] && [ $1 != "tmp.gpg" ]; then
printf "%s\n" "Invalid keyring $1"
return 1
fi
gpg --keyring $1 --no-default-keyring --keyserver hkps://keys.openpgp.org --search-keys $2
}
# Import public key
function import() {
if [ -z "$1" ]; then
printf "%s\n" "Usage: import [keyring] /path/to/pubkey.asc"
return 1
fi
if [ -z "$2" ]; then
2=$1
1=pubring.gpg
fi
if [ $1 != "pubring.gpg" ] && [ $1 != "tmp.gpg" ]; then
printf "%s\n" "Invalid keyring $1"
return 1
fi
gpg --keyring $1 --no-default-keyring --import $2
}
# List public keys
function list-keys() {
if [ -z "$1" ]; then
1=pubring.gpg
fi
if [ $1 != "pubring.gpg" ] && [ $1 != "tmp.gpg" ]; then
printf "%s\n" "Invalid keyring $1"
return 1
fi
gpg --keyring $1 --no-default-keyring --list-keys $2
}
# Encrypt message for id
function encrypt() {
if [ -z "$1" ]; then
printf "%s\n" "Usage: encrypt id"
return 1
fi
gpg --keyring "tmp.gpg" --encrypt --sign --armor -r 0xC1323A377DE14C8B -r $1
}
# Decrypt and decode encrypted file
function decrypt() {
if [ -z "$1" ]; then
printf "%s\n" "Usage: decrypt /path/to/encrypted.asc"
return 1
fi
gpg --decrypt $1 | perl -MMIME::QuotedPrint -0777 -nle 'print decode_qp($_)'
}
替换0xC1323A377DE14C8B
为您的公钥。