Skip to content

Instantly share code, notes, and snippets.

@macostag
Created May 7, 2018 04:12
Show Gist options
  • Select an option

  • Save macostag/a8537a75f3e43e4eb0cb1552f6ddb15a to your computer and use it in GitHub Desktop.

Select an option

Save macostag/a8537a75f3e43e4eb0cb1552f6ddb15a to your computer and use it in GitHub Desktop.
AES Encrypt/Decrypt demo
import os
from Crypto.Cipher import AES
counter = os.urandom(16)
#AES keys may be 128 bits (16 bytes), 192 bits (24 bytes) or 256 bits (32 bytes) long.
key = os.urandom(32)
# AES Encrypt
enc = AES.new(key, AES.MODE_CTR, counter=lambda: counter)
encrypted = enc.encrypt("Secret")
print encrypted
# AES Decrypt
dec = AES.new(key, AES.MODE_CTR, counter=lambda: counter)
decrypted = dec.decrypt(encrypted)
print decrypted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment