【发布时间】:2016-06-29 08:16:53
【问题描述】:
This is my code for encrypting a file:
我收到以下错误“cipher_aes = AES.new(session_key, AES.MODE_EAX) AttributeError:“模块”对象没有属性“MODE_EAX”” 如果我从第 10 行删除“AES.MODE_EAX”,那么我在第 12 行收到以下错误(密文,标签 = cipher_aes.encrypt_and_digest(data) AttributeError:AESCipher 实例没有属性“encrypt_and_digest”)
from Crypto.PublicKey import RSA
from Crypto.Random import get_random_bytes
from Crypto.Cipher import AES, PKCS1_OAEP
with open('encrypted_data.bin', 'wb') as out_file:
recipient_key = open('public.pem').read()
recipient_key=RSA.importKey(recipient_key)
session_key = get_random_bytes(16)
cipher_rsa = PKCS1_OAEP.new(recipient_key)
out_file.write(cipher_rsa.encrypt(session_key))
cipher_aes = AES.new(session_key, AES.MODE_EAX)
data = b'blah blah blah Python blah blah'
ciphertext, tag = cipher_aes.encrypt_and_digest(data)
out_file.write(cipher_aes.nonce)
out_file.write(tag)
out_file.write(ciphertext)
【问题讨论】:
标签: python cryptography public-key-encryption