Skip to content

Instantly share code, notes, and snippets.

@bulatie
Created May 13, 2019 07:59
Show Gist options
  • Save bulatie/72e1681b5f8393fb51dce377e8dab509 to your computer and use it in GitHub Desktop.
Save bulatie/72e1681b5f8393fb51dce377e8dab509 to your computer and use it in GitHub Desktop.
aes cfb mode py2
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