I have followed to encrypt username and password AES in React based on the below link https://www.code-sample.com/2019/12/react-encryption-decryption-data-text.html using crypto-js
const encryptedUsername = CryptoJS.AES.encrypt(usernameWithoutSpaces, SECRET_KEY).toString();
const encryptedPassword = CryptoJS.AES.encrypt(values.password, SECRET_KEY).toString();
I have used the SECRET_KEY as 16byte code which I randomly generated. And used this key for both encrypt and decrypt.
I have followed the decryption based on https://devrescue.com/python-aes-cbc-decrypt-example/
from Crypto.Cipher import AES
from Crypto.Util.Padding import unpad
import base64
def decrypt_view(request):
encrypted_username = request.data['username']
encrypted_password =request.data['password']
secret_key =b'53d7311e6f8f88c0bbc4a08bccd7e254'
decrypted_username = decrypt_data(encrypted_username, secret_key)
decrypted_password = decrypt_data(encrypted_password, secret_key)
def decrypt_data(encrypted_data, key):
try:
cipher = AES.new(key, AES.MODE_CBC, iv=b'1234567890123456')
decrypted_data =
unpad(cipher.decrypt(base64.b64decode(encrypted_data)),
AES.block_size)
# print("&&&&&&&&&&&&&&",decrypted_data)
return decrypted_data.decode('utf-8')
except Exception as e:
print("DDDDDDDDDDDDDDD",e)
with this encryption done at frontend and at backend couldn't decrypt as Error which i got as Padding is incorrect. Padding is incorrect.
I have also used cryptography module and fernet which is in python to perform decryption. hence it doesnt suite with crypto-js.