Skip to content

Instantly share code, notes, and snippets.

@bulatie
Created May 13, 2019 07:56
Show Gist options
  • Select an option

  • Save bulatie/7139fb05f94a1596d522129db679f307 to your computer and use it in GitHub Desktop.

Select an option

Save bulatie/7139fb05f94a1596d522129db679f307 to your computer and use it in GitHub Desktop.
aes cfb mode py3
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