我正在尝试加密字符串。但出现此错误:-
ValueError:AES密钥必须为16、24或32个字节长
from Crypto.Cipher import AES
import hashlib
key = 'E61EFD66173C8A58132B84E43566AB4826533F4483968BA58C9C4739FFD25FAD'
firstByte = key[0:32]
lastByte = key[32:64]
hexfirstByte = firstByte.encode()
hexlastByte = lastByte.encode()
# xorNumber = int(firstByte,2) ^ int(lastByte,2)
xorNumber = hex(int(firstByte,16) ^ int(lastByte,16))
hexNumber = bytes(xorNumber, 'utf-8')
IV = 16 * '\x00'
mode = AES.MODE_CBC
encryptor = AES.new(hexNumber, mode, IV=IV)
text = 'j' * 64 + 'i' * 128
ciphertext = encryptor.encrypt(text)
decryptor = AES.new(hexNumber, mode, IV=IV)
plain = decryptor.decrypt(ciphertext)
print("decript" + str(plain))