(plain_text: str)
| 12 | |
| 13 | |
| 14 | def aes_encrypt(plain_text: str): |
| 15 | if not AES_ENCRYPTION_KEY_BYTES: |
| 16 | raise Exception("AES_ENCRYPTION_KEY is not set") |
| 17 | cipher = AES.new(AES_ENCRYPTION_KEY_BYTES, AES.MODE_CBC) |
| 18 | ct_bytes = cipher.encrypt(pad(plain_text.encode(), AES.block_size)) |
| 19 | iv = b64encode(cipher.iv).decode("utf-8") |
| 20 | ct = b64encode(ct_bytes).decode("utf-8") |
| 21 | return f"{iv},{ct}" |
| 22 | |
| 23 | |
| 24 | def aes_decrypt(encrypted_text: str): |