xotohop Dec 8th, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- import hashlib
- from Crypto.Cipher import AES
- from Crypto.Random import get_random_bytes
- password = 'qwerty1337'
- key_sha256 = hashlib.sha256((password).encode('utf-8')).hexdigest()
- data = b'blah blah blah'
- # 16, 24 or 32 bytes
- key_rndbytes = get_random_bytes(24)
- cipher = AES.new(key_rndbytes, AES.MODE_EAX) # or key_sha256
- ciphertext, tag = cipher.encrypt_and_digest(data)
- file_out = open("encrypted.bin", "wb")
- [ file_out.write(x) for x in (cipher.nonce, tag, ciphertext) ]
RAW Paste Data