简体   繁体   English

AES CBC 解密中的错误 65537

[英]Error 65537 in AES CBC decryption

I am currently doing a course on Coursera - Cryptography - I. There is an optional assignment, I am facing a syntactical issue with the library mentioned in it.我目前正在学习 Coursera - Cryptography - 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)

In the statement obj = AES.new(key, AES.MODE_CBC, iv) it throws an error ValueError: Error 65537 while instatiating the CBC mode Any fixes?在语句obj = AES.new(key, AES.MODE_CBC, iv) ,它会引发错误ValueError: Error 65537 while instatiating the CBC mode任何修复吗?

The values are encoded as hex strings.这些值被编码为十六进制字符串。 You need to use the decoded arrays of bytes.您需要使用解码后的 arrays 字节。

Transform them with these lines, ahead of constructing your AES :在构建AES之前,用这些行转换它们:

key = bytes.fromhex(key.decode('us-ascii'))
iv = iv.fromhex(iv.decode('us-ascii'))
cipher = cipher.fromhex(cipher.decode('us-ascii'))

(Or, simpler, define them as regular strings to avoid the need to .decode('us-ascii') .) (或者,更简单,将它们定义为常规字符串以避免需要.decode('us-ascii') 。)

And you'll get:你会得到:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM