Created
May 13, 2019 07:59
-
-
Save bulatie/72e1681b5f8393fb51dce377e8dab509 to your computer and use it in GitHub Desktop.
aes cfb mode py2
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 = "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) | |
result = json.dumps({'ciphertext':ct}) | |
print(result) | |
cipher = AES.new(key, AES.MODE_CFB, iv) | |
pt = cipher.decrypt(ct_bytes) | |
print("The message was: ", pt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment