Ritesh's Blog

Python AES

Cryptography isn’t available by default on python. One needs to install the PyCrypto toolkit to make it work. Looks something like this:

from Crypto.Cipher import AES   
import base64   
  
key = "x0Dx0Fx07x0Fx0Cx0Fx08x0Fx06x0Fx09x0Fx06x0Fx03x0Fx0Fx06x0Fx0Fx0Fx0Fx0Fx0Fx06x0Fx09x0Fx06x0Fx03x0F"   
objAes=AES.new(key, AES.MODE_ECB)   
plaintext='This is sparta!!'   
#looks nicer with base64   
enc = objAes.encrypt(plaintext)   
print "Encrypted: " + base64.b64encode(enc)   
print "Decrypted: " + objAes.decrypt(enc)   

Reply to this post by email ↪