What (pure) Python library to use for AES 256 encryption?

Daren Thomas picture Daren Thomas · Oct 5, 2008 · Viewed 30.7k times · Source

I am looking for a (preferably pure) python library to do AES 256 encryption and decryption.

This library should support the CBC cipher mode and use PKCS7 padding according to the answer to an earlier question of mine.

The library should at least work on Mac OS X (10.4) and Windows XP. Ideally just by dropping it into the source directory of my project. I have seen this by Josh Davis, but am not sure about how good it is and if it does the required CBC cipher mode... Scanning the source suggests it doesn't

Answer

caller9 picture caller9 · Jan 19, 2011

https://github.com/caller9/pythonaes

That is pure python with PKCS7 padding. Supports CBC, CFB, and OFB modes.

The problem is that python is not super fast for this type of thing. The code from serprex's fork is a little bit inscrutable, but much faster than mine due to using all kinds of tricks to squeeze every last bit of speed out of Python.

Really though, the best libraries for this are compiled and hook into SSE/MMX stuff.

Also Intel is baking in AES instructions since the Core(tm) line of chips.

I wrote my version to get a true pure Python version out there to be able to run on any architecture, cross-platform, and with 3.x as well as 2.7.