Skip to content

Instantly share code, notes, and snippets.

@jbdatko
jbdatko / gcm.py
Created November 12, 2013 04:23
Example of pycrypto CCM mode
from Crypto.Cipher import AES
from Crypto.Random import get_random_bytes
hdr = b'To your eyes only'
plaintext = b'Attack at dawn'
key = b'Sixteen byte key'
nonce = get_random_bytes(11)
cipher = AES.new(key, AES.MODE_CCM, nonce)
cipher.update(hdr)
msg = nonce, hdr, cipher.encrypt(plaintext), cipher.digest()