· 7 years ago · Nov 28, 2018, 09:08 AM
1from Crypto.Cipher import AES
2import base64
3
4msg_text = b'test some plain text here'.rjust(32)
5secret_key = b'1234567890123456' # create new & store somewhere safe
6
7cipher = AES.new(secret_key,AES.MODE_ECB) # never use ECB in strong systems obviously
8encoded = base64.b64encode(cipher.encrypt(msg_text))
9print(encoded)
10# ...
11decoded = cipher.decrypt(base64.b64decode(encoded))
12print(decoded.strip())