AES CBC解密报错65537

Error 65537 in AES CBC decryption

我目前正在上 Coursera - 密码学 - I 的课程。有一个可选作业,我正面临其中提到的库的句法问题。

from Crypto.Cipher import AES

key = b'140b41b22a29beb4061bda66b6747e14'
iv = b'4ca00ff4c898d61e1edbf1800618fb28'
cipher = b'28a226d160dad07883d04e008a7897ee2e4b7465d5290d0c0e6c6822236e1daafb94ffe0c5da05d9476be028ad7c1d81'

obj = AES.new(key, AES.MODE_CBC, iv)

answer = obj.decrypt(cipher)
print(answer)

在声明中obj = AES.new(key, AES.MODE_CBC, iv) 它抛出一个错误 ValueError: Error 65537 while instatiating the CBC mode 有任何修复吗?

这些值被编码为十六进制字符串。您需要使用解码后的字节数组。

在构建您的 AES:

之前用这些行转换它们
key = bytes.fromhex(key.decode('us-ascii'))
iv = iv.fromhex(iv.decode('us-ascii'))
cipher = cipher.fromhex(cipher.decode('us-ascii'))

(或者,更简单,将它们定义为常规字符串以避免需要 .decode('us-ascii')。)

你会得到:

b'Basic CBC mode encryption needs padding.\x08\x08\x08\x08\x08\x08\x08\x08'