Created
May 7, 2018 04:12
-
-
Save macostag/a8537a75f3e43e4eb0cb1552f6ddb15a to your computer and use it in GitHub Desktop.
AES Encrypt/Decrypt demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| from Crypto.Cipher import AES | |
| counter = os.urandom(16) | |
| #AES keys may be 128 bits (16 bytes), 192 bits (24 bytes) or 256 bits (32 bytes) long. | |
| key = os.urandom(32) | |
| # AES Encrypt | |
| enc = AES.new(key, AES.MODE_CTR, counter=lambda: counter) | |
| encrypted = enc.encrypt("Secret") | |
| print encrypted | |
| # AES Decrypt | |
| dec = AES.new(key, AES.MODE_CTR, counter=lambda: counter) | |
| decrypted = dec.decrypt(encrypted) | |
| print decrypted |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment