Decrypt the AES encrypted string. Parameters: ciphertext -- Encrypted string with AES method. key -- key to decrypt the encrypted string.
(ciphertext, key)
| 45 | |
| 46 | |
| 47 | def decrypt(ciphertext, key): |
| 48 | """ |
| 49 | Decrypt the AES encrypted string. |
| 50 | |
| 51 | Parameters: |
| 52 | ciphertext -- Encrypted string with AES method. |
| 53 | key -- key to decrypt the encrypted string. |
| 54 | """ |
| 55 | |
| 56 | ciphertext = base64.b64decode(ciphertext) |
| 57 | iv = ciphertext[:iv_size] |
| 58 | |
| 59 | cipher = Cipher(AES(pad(key)), CFB8(iv), default_backend()) |
| 60 | decryptor = cipher.decryptor() |
| 61 | return decryptor.update(ciphertext[iv_size:]) + decryptor.finalize() |
| 62 | |
| 63 | |
| 64 | def pad(key): |