Python3使用AES报错ValueError: Incorrect AES key length (95 bytes)

Traceback (most recent call last):
File “C:\Users\billl\AppData\Local\Continuum\anaconda3\lib\site-packages\IPython\core\interactiveshell.py”, line 2963in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File “”, line 1in 
AES.new(“asssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssdfasasasasa”, AES.MODE_ECB)
File “C:\Users\billl\AppData\Local\Continuum\anaconda3\lib\site-packages\Crypto\Cipher\AES.py”, line 232in new
return create_cipher(sys.modules[name], keymode, *args, **kwargs)
File "C:\Users\billl\AppData\Local\Continuum\anaconda3\lib\site-packages\Crypto\Cipher_init.py", line 79in _create_cipher
return modes[mode](factory, **kwargs)
File “C:\Users\billl\AppData\Local\Continuum\anaconda3\lib\site-packages\Crypto\Cipher_mode_ecb.py”, line 215in _create_ecb_cipher
cipher_state = factory._create_base_cipher(kwargs)
File “C:\Users\billl\AppData\Local\Continuum\anaconda3\lib\site-packages\Crypto\Cipher\AES.py”, line 93in _create_base_cipher
raise ValueError(“Incorrect AES key length (%d bytes)” % len(key))
ValueError: Incorrect AES key length (95 bytes)

这个报错是说AES的KEY长度超过了限制

除了MODE_SIV模式key长度为:32, 48, or 64,
其余key长度为16, 24 or 32
内部函数说明:

“”"Create a new AES cipher.

:param key:
    The secret key to use in the symmetric cipher.

    It must be 16, 24 or 32 bytes long (respectively for *AES-128*,
    *AES-192* or *AES-256*).

    For ``MODE_SIV`` only, it doubles to 32, 48, or 64 bytes.
:type key: bytes/bytearray/memoryview

:param mode:
    The chaining mode to use for encryption or decryption.
    If in doubt, use ``MODE_EAX``.
:type mode: One of the supported ``MODE_*`` constants

ID:Python之战

|作|者|公(zhong)号:python之战

专注Python,专注于网络爬虫、RPA的学习-践行-总结

喜欢研究和分享技术瓶颈,欢迎关注

独学而无友,则孤陋而寡闻!


猜你喜欢

转载自blog.csdn.net/weixin_41624982/article/details/85257387