我正在使用pycrypto模块进行AES加密。并使用文档我已经写下了下面的函数,但它的方式给出了错误IV must be 16 bytes long
,但我使用16字节长的IV。IV必须是AES加密中的16字节长错误
def aes_encrypt(plaintext):
"""
"""
key = **my key comes here**
iv = binascii.hexlify(os.urandom(16)) # even used without binascii.hexlify)
aes_mode = AES.MODE_CBC
obj = AES.new(key, aes_mode, iv)
ciphertext = obj.encrypt(plaintext)
return ciphertext
应该没有hexlify工作。再试一次,看看你是否得到相同的错误信息。 – interjay
删除'binascii.hexlify'为我解决它。 –
nop,它不起作用 – user5594493