from Crypto.Cipher import AES from Crypto import Random key = b'dzaaaaaaaaaaaaaa' cipher = AES.new(key, AES.MODE_CFB, key) msg = cipher.encrypt(b'This is the secret message ') open("output.aes", "w").write(msg) # decryption # To get rid of leading gibberish, re-make the object # Why? Think about the initialization vector and CFB key = b'dzaaaaaaaaaaaaaa' cipher = AES.new(key, AES.MODE_CFB, key) print cipher.decrypt(open("output.aes").read())