|
|
@@ -35,8 +35,10 @@ def secure_transport(view_func):
|
|
|
aes_key = private_cipher.decrypt(base64.b64decode(enc_key.encode('utf-8')), b'error').decode('utf-8')
|
|
|
print(f'key={aes_key}')
|
|
|
|
|
|
- aes_cipher = AES.new(aes_key.encode('utf-8'), AES.MODE_CBC, IV.encode('utf-8'))
|
|
|
- decrypted = aes_cipher.decrypt(base64.b64decode(cipher_text.encode('utf-8')))
|
|
|
+ def get_aes_cipher():
|
|
|
+ return AES.new(aes_key.encode('utf-8'), AES.MODE_CBC, IV.encode('utf-8'))
|
|
|
+
|
|
|
+ decrypted = get_aes_cipher().decrypt(base64.b64decode(cipher_text.encode('utf-8')))
|
|
|
# print(decrypted)
|
|
|
decrypted = decrypted[:-decrypted[-1]]
|
|
|
# print(decrypted)
|
|
|
@@ -55,14 +57,14 @@ def secure_transport(view_func):
|
|
|
|
|
|
raw_response = view_func(dec_request, *args, **kwargs)
|
|
|
|
|
|
- content = json.dumps({'data': raw_response.content.decode('utf-8')})
|
|
|
+ content = json.dumps({'data': json.loads(raw_response.content)}).encode('utf-8')
|
|
|
padding = 16 - len(content) % 16
|
|
|
content += bytes([padding] * padding)
|
|
|
print(content)
|
|
|
|
|
|
- aes_cipher = AES.new(aes_key.encode('utf-8'), AES.MODE_CBC, IV.encode('utf-8'))
|
|
|
- enc_content = base64.b64encode(aes_cipher.encrypt(content)).decode('utf-8')
|
|
|
+ enc_content = base64.b64encode(get_aes_cipher().encrypt(content)).decode('utf-8')
|
|
|
print(enc_content)
|
|
|
+ print(get_aes_cipher().decrypt(base64.b64decode(enc_content.encode('utf-8'))))
|
|
|
return make_json_response(enc_content=enc_content)
|
|
|
return _wrapped_view
|
|
|
|