Created
May 13, 2019 07:56
-
-
Save bulatie/7139fb05f94a1596d522129db679f307 to your computer and use it in GitHub Desktop.
aes cfb mode py3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| from base64 import b64encode | |
| from Crypto.Cipher import AES | |
| from Crypto.Random import get_random_bytes | |
| data = b"secret" | |
| print(data) | |
| key = get_random_bytes(16) | |
| iv = get_random_bytes(16) | |
| cipher = AES.new(key, AES.MODE_CFB, iv) | |
| ct_bytes = cipher.encrypt(data) | |
| ct = b64encode(ct_bytes).decode('utf-8') | |
| result = json.dumps({'ciphertext':ct}) | |
| print(result) | |
| cipher = AES.new(key, AES.MODE_CFB, iv) | |
| pt = cipher.decrypt(ct_bytes) | |
| rr = pt.decode("utf-8") | |
| print("The message was: ", rr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment