python3 aes cbc模式解密_Python中的AES-128 CBC解密

在Python3中实现AES-128 CBC模式解密时遇到错误,包括‘str’对象没有'decode'属性和IV必须为16字节长。解决方案是使用binascii模块的unhexlify进行十六进制字符串到字节的转换。通过修改代码,成功完成解密并验证了解密的正确性。
摘要由CSDN通过智能技术生成

I'm trying to implement this code in python (I'm new to python) and it gives me the following error:

AttributeError: 'str' object has no attribute 'decode'

If we remove .decode ('hex') only to avoid such error:

from itertools import product

from Crypto.Cipher import AES

import Crypto.Cipher.AES

key = ('2b7e151628aed2a6abf7158809cf4f3c').decode('hex')

IV = ('000102030405060708090a0b0c0d0e0f').decode('hex')

plaintext1 = ('6bc1bee22e409f96e93d7e117393172a').decode('hex')

plaintext2 = ('ae2d8a571e03ac9c9eb76fac45af8e51').decode('hex')

plaintext3 = ('30c81c46a35ce411e5fbc1191a0a52ef').decode('hex')

cipher = AES.new(key, AES.MODE_CBC, IV)

ciphertext = cipher.encrypt(pl

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值