我正在尝试使用pycryptodome示例来加密带有RSA密钥的文件。示例如下所示
from Crypto.PublicKey import RSA
from Crypto.Random import get_random_bytes
from Crypto.Cipher import AES, PKCS1_OAEP
file_out = open("encrypted_data.bin", "wb")
recipient_key = RSA.import_key(open("receiver.pem").read())
session_key = get_random_bytes(16)
# Encrypt the session key with the public RSA key
cipher_rsa = PKCS1_OAEP.new(recipient_key)
file_out.write(cipher_rsa.encrypt(session_key))
# Encrypt the data with the AES session key
cipher_aes = AES.new(session_key, AES.MODE_EAX)
ciphertext, tag = cipher_aes.encrypt_and_digest(data)
[ file_out.write(x) for x in (cipher.nonce, tag, ciphertext) ]我收到的错误是
AttributeError:模块“Crypto.PublicKey.RSA”没有属性“import_key”
我发现了另一个线程,在这个线程中,这个错误被认为是pyCrypto的版本问题,但是我尝试使用PyCryptodome,我确实有最新的版本。
发布于 2017-11-14 12:20:42
在import_key中加入PyCryptodome v3.4方法。如果您收到了该错误消息,这意味着您实际上正在使用PyCrypto或较早版本的PyCryptodome。
https://stackoverflow.com/questions/47218780
复制相似问题