简单的 PGP 加密只需一步?

简单的 PGP 加密只需一步?

我想对文件运行 gpg 加密,而根本不需要在系统中注册密钥。

理想情况下,有一种方法可以传递密钥文件的路径并对目标文件运行加密。

有办法吗?我正在运行 CentOS Linux。

答案1

只要有强大的意志,必有一条路为你开...

将以下内容保存为可执行脚本,随意命名。(我称之为G。)

#!/bin/bash
# Requires pubkey_file as 1st arg
# Will automatically set encrypt recip to first pub key found in keyring
# Passes all additional args to gpg
g=$(mktemp -d) && trap "rm -rf $g" EXIT || exit 255                                                                                                                                
gpg --homedir $g --import "$1" 2>&1 | awk /key.\*imported/ >&2
shift
keyid=$(gpg --homedir $g -k --with-colons 2>/dev/null| awk -F: /^pub/{print\$5})
if [[ -n $keyid ]]; then
  gpg --homedir $g --trust-model always -ver $keyid "$@"
else
  echo "Could not find pubkey in imported keyring" >&2
fi

以下是我的使用方法:

[ryran]$ gpg -k
[ryran]$ G /tmp/barackskey.asc /tmp/hhwchk.orig
gpg: key 6B004035: public key "Barack Obama <bo@devnull>" imported
gpg: using subkey 457D05AC instead of primary key 6B004035
gpg: No trust check due to `--trust-model always' option
gpg: reading from `/tmp/hhwchk.orig'
gpg: writing to `/tmp/hhwchk.orig.gpg'
gpg: ELG-E/AES256 encrypted for: "457D05AC Barack Obama <bo@devnull>"
[ryran]$ 
[ryran]$ gpg -k
[ryran]$ G /tmp/barackskey.asc -ao- /etc/issue
gpg: key 6B004035: public key "Barack Obama <bo@devnull>" imported
gpg: using subkey 457D05AC instead of primary key 6B004035
gpg: No trust check due to `--trust-model always' option
gpg: reading from `/etc/issue'
gpg: writing to `-'
gpg: ELG-E/AES256 encrypted for: "457D05AC Barack Obama <bo@devnull>"
-----BEGIN PGP MESSAGE-----
Version: GnuPG v1.4.12 (GNU/Linux)

hQEOA5S5GiBFfQWsEAP+LTru/pgYPOzMDbc6xPbFUcSjq6qBzKvZ4Smf0P1IKesi
9u7P3zq5njsRKMjdKH71EaRMUTOcrTKzRH0iEoYtVSeWUlR1oHNKZewZUXNknRHu
AWc1SLHxrULisl6CenL0u0glQ8/Q4RNCXxeplqMXdtnocig/VGLLTsY1UKCMgtgE
AJDXinycZpOv1nl9UgW6h8e0ifO/txPTmleW2GRMIRCfs59gNYR13x+oGi1EkL6y
rSLicknLj/uQ1a8d8C/4nDEAtGyhtOYzP5SavTOLPR+jr5NrbCNvmKBOmSXCU1y+
KrZpsOxGdNxoIuGEpYlTOZV//BUHStNLv/Szf+pggtfX0nEB1zdMLzK2p0JcJXIs
Jz9PNmNsHZUr5Zys11xe8wx4X+yjMGHt6kqqoPABau1ETDR7J23vguDKAh68rMX7
2doxof/vKEksB8mzePdIh0cUnZqYWurtm/hX02wszJ5bHKPKjKJwl+YRWSG5YWUY
M4h20w==
=1/2D
-----END PGP MESSAGE-----

相关内容