首页 > 解决方案 > /shop/checkout/ 处的 ValueError 不正确的 AES 密钥长度(22 字节)

问题描述

此代码在服务器端给出无效的 AES 密钥长度错误。我该如何纠正?之后,当从客户端服务器发送 msg 出错时,服务器将被创建。

服务器代码:

File "/home/saurabh/.local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)

File "/home/saurabh/.local/lib/python3.6/site-packages/django/core/handlers/base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)

File "/home/saurabh/.local/lib/python3.6/site-packages/django/core/handlers/base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/home/saurabh/project/myshop/shopingsite/shop/views.py", line 126, in checkout
    param_dict['CHECKSUMHASH'] = Checksum.generate_checksum(param_dict, MERCHANT_KEY)

File "/home/saurabh/project/myshop/shopingsite/PayTm/Checksum.py", line 24, in generate_checksum
    return __encode__(hash_string, IV, merchant_key)

File "/home/saurabh/project/myshop/shopingsite/PayTm/Checksum.py", line 103, in __encode__
    c = AES.new(key.encode('utf-8'), AES.MODE_CBC, iv.encode('utf-8'))

File "/home/saurabh/.local/lib/python3.6/site-packages/Crypto/Cipher/AES.py", line 232, in new
    return _create_cipher(sys.modules[__name__], key, mode, *args, **kwargs)

File "/home/saurabh/.local/lib/python3.6/site-packages/Crypto/Cipher/__init__.py", line 79, in _create_cipher
    return modes[mode](factory, **kwargs)

File "/home/saurabh/.local/lib/python3.6/site-packages/Crypto/Cipher/_mode_cbc.py", line 274, in _create_cbc_cipher
    cipher_state = factory._create_base_cipher(kwargs)

File "/home/saurabh/.local/lib/python3.6/site-packages/Crypto/Cipher/AES.py", line 93, in _create_base_cipher
    raise ValueError("Incorrect AES key length (%d bytes)" % len(key))

ValueError: Incorrect AES key length (22 bytes)
[01/Apr/2020 06:33:08] "POST /shop/checkout/ HTTP/1.1" 500 101430

标签: pythondjango

解决方案


推荐阅读