Python 属性错误:模块';加密.Cipher.AES';没有属性';块大小';

Python 属性错误:模块';加密.Cipher.AES';没有属性';块大小';,python,aes,Python,Aes,我正在尝试使用Python3进行AES加密 我已执行以下代码,并出现以下错误: 属性错误:模块“Crypto.Cipher.AES”没有属性“block\u size” 我在谷歌上冲浪和搜索了很多次,但没有找到解决方案 有人能帮忙吗 from hashlib import md5 from base64 import b64decode from base64 import b64encode from Crypto.Cipher import AES from Crypto.Random i

我正在尝试使用Python3进行AES加密

我已执行以下代码,并出现以下错误:

属性错误:模块“Crypto.Cipher.AES”没有属性“block\u size”

我在谷歌上冲浪和搜索了很多次,但没有找到解决方案

有人能帮忙吗

from hashlib import md5
from base64 import b64decode
from base64 import b64encode

from Crypto.Cipher import AES
from Crypto.Random import get_random_bytes
from Crypto.Util.Padding import pad, unpad


class AESCipher:
    def __init__(self, key):
        self.key = md5(key.encode('utf8')).digest()

    def encrypt(self, data):
        iv = get_random_bytes(AES.block_size)
        self.cipher = AES.new(self.key, AES.MODE_CBC, iv)
        return b64encode(iv + self.cipher.encrypt(pad(data.encode('utf-8'),
            AES.block_size)))

    def decrypt(self, data):
        raw = b64decode(data)
        self.cipher = AES.new(self.key, AES.MODE_CBC, raw[:AES.block_size])
        return unpad(self.cipher.decrypt(raw[AES.block_size:]), AES.block_size)


if __name__ == '__main__':
    print('TESTING ENCRYPTION')
    msg = input('Message...: ')
    pwd = input('Password..: ')
    print('Ciphertext:', AESCipher(pwd).encrypt(msg).decode('utf-8'))

    print('\nTESTING DECRYPTION')
    cte = input('Ciphertext: ')
    pwd = input('Password..: ')
    print('Message...:', AESCipher(pwd).decrypt(cte).decode('utf-8'))

你有什么版本的PyCrypto?当前在AES模块中有
block\u size
(证明和)在使用PyCryptodome的Python3上不可复制,请参阅replit上的联机:。如果您真的应用了传统的PyCrypto,那么应该切换到PyCryptodome。顺便说一句,摘要,尤其是MD5,作为密钥派生函数(KDF)是不安全的,最好使用可靠的KDF(Argon2、PBKDF2等)。@Crisal我应该使用哪个版本?我目前正在使用PyCryptodome@topaco我已经尝试过沙盒代码,但它仍然向我显示错误。