Skip to content

Instantly share code, notes, and snippets.

@tiran
Created February 24, 2014 20:40
Show Gist options
  • Save tiran/9196564 to your computer and use it in GitHub Desktop.
Save tiran/9196564 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python2.7
import os
from PIL import Image
from Crypto.Cipher import AES
# random key
key = os.urandom(16)
# load image
img = Image.open("militarygrade.png")
# encrypt
cipher = AES.new(key)
cdata = cipher.encrypt(img.tobytes())
# create image from encrypted data
cimg = Image.frombytes(img.mode, img.size, cdata)
cimg.save("militarygrade_encrypted.png")
cimg.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment