文字列型の値を暗号化しようとすると、次のエラーが発生します。ValueErrorを取得中:DjangoとPythonを使用して暗号化と復号化を使用中
エラー:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/opt/lampp/htdocs/d30/carClinic_vulnerable/bookingservice/views.py", line 141, in signsave
obj = AES.new('this is a carkey123', AES.MODE_CBC, 'This is an IV456')
File "/usr/lib/python2.7/dist-packages/Crypto/Cipher/AES.py", line 94, in new
return AESCipher(key, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/Crypto/Cipher/AES.py", line 59, in __init__
blockalgo.BlockAlgo.__init__(self, _AES, key, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/Crypto/Cipher/blockalgo.py", line 141, in __init__
self._cipher = factory.new(key, *args, **kwargs)
ValueError: AES key must be either 16, 24, or 32 bytes long
私は以下の私のコードを説明しています。
name = request.POST.get('uname')
obj = AES.new('this is a carkey123', AES.MODE_CBC, 'This is an IV456')
enpass = obj.encrypt(name)
エラーはやや自明です。 [key引数](http://pythonhosted.org/pycrypto/Crypto.Cipher.AES-module.html#new)は、16,24、または32バイトのバイト文字列でなければなりません。あなたは19バイトです。 –