创建PGP密钥
加密消息
解密消息
当前代码如下:import string
import random
import gnupg
random_string_length = 20
random_gpg_key_passphrase = "".join(
random.SystemRandom().choice(string.ascii_letters + string.digits) for _ in range(random_string_length))
gpg = gnupg.GPG(homedir="gpg")
cs_gpg_key_input_dict = {
"key_type": "RSA",
"key_length": 4096,
"passphrase": random_gpg_key_passphrase
}
python_gnupg_key_generation_input_data = gpg.gen_key_input(**cs_gpg_key_input_dict)
gpg_key_pair = gpg.gen_key(python_gnupg_key_generation_input_data)
encrypted_data = gpg.encrypt("message", gpg_key_pair.fingerprint,
passphrase=random_gpg_key_passphrase, always_trust=True)
msg = str(encrypted_data)
decrypted_data = gpg.decrypt(msg, passphrase=random_gpg_key_passphrase, always_trust=True)
不幸的是,加密返回错误:raise ValueError("Unknown status message: %r" % key)
ValueError: Unknown status message: 'ENCRYPTION_COMPLIANCE_MODE'
但是它仍然会生成加密的ASCII装甲消息Hovewer解密会导致Crypt对象具有False属性的ok bool值,并跟随stderr属性:[GNUPG:] ENC_TO 1 0
[GNUPG:] KEY_CONSIDERED 0
[GNUPG:] PINENTRY_LAUNCHED 7570 gnome3:curses 1.1.0 - - :0
[GNUPG:] KEY_CONSIDERED 0
gpg: encrypted with 4096-bit RSA key, ID , created 2019-10-01
"ZZZ"
gpg: public key decryption failed: Inappropriate ioctl for device
[GNUPG:] ERROR pkdecrypt_failed
[GNUPG:] BEGIN_DECRYPTION
[GNUPG:] DECRYPTION_FAILED
gpg: decryption failed: No secret key
[GNUPG:] END_DECRYPTION
不确定错误在哪里发生以及如何处理