From 1002d446155c5b87c1c94a3fd021c33faff00c6b Mon Sep 17 00:00:00 2001 From: juuso-j Date: Fri, 15 Mar 2024 14:57:18 +0200 Subject: [PATCH] Set Initial Vector --- profiles/utils.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/profiles/utils.py b/profiles/utils.py index cdc3460..7186fae 100644 --- a/profiles/utils.py +++ b/profiles/utils.py @@ -10,15 +10,12 @@ def encrypt_text(text, key): - cipher = AES.new(key.encode("utf-8"), AES.MODE_CBC) - # Pad the text to make its length a multiple of 16 bytes (AES block size) - padded_text = pad(text.encode("utf-8"), AES.block_size) - # Encrypt the padded text - encrypted_bytes = cipher.encrypt(padded_text) - # Encode the encrypted bytes in base64 - encrypted_text = base64.b64encode(encrypted_bytes).decode("utf-8") - - return encrypted_text + text = pad(text.encode(), 16) + iv = "BBBBBBBBBBBBBBBB".encode("utf-8") + cipher = AES.new(key.encode("utf-8"), AES.MODE_CBC, iv) + return base64.b64encode(cipher.encrypt(text)), base64.b64encode(cipher.iv).decode( + "utf-8" + ) def get_user_result(user: User) -> Result: