(encrypted_text: str)
| 22 | |
| 23 | |
| 24 | def aes_decrypt(encrypted_text: str): |
| 25 | if not AES_ENCRYPTION_KEY_BYTES: |
| 26 | raise Exception("AES_ENCRYPTION_KEY is not set") |
| 27 | if encrypted_text is None or "," not in encrypted_text: |
| 28 | return None |
| 29 | iv, ct = encrypted_text.split(",", 1) |
| 30 | iv = b64decode(iv) |
| 31 | ct = b64decode(ct) |
| 32 | cipher = AES.new(AES_ENCRYPTION_KEY_BYTES, AES.MODE_CBC, iv) |
| 33 | pt = unpad(cipher.decrypt(ct), AES.block_size) |
| 34 | return pt.decode("utf-8") |
| 35 | |
| 36 | |
| 37 | def generate_aes_encryption_key(): |