ValueError:AES密钥在Python中必须为16、24或32个字节长的错误

时间:2019-12-11 05:44:13

标签: python python-3.x aes xor

我正在尝试加密字符串。但出现此错误:-

  

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))

0 个答案:

没有答案