SHARE
TWEET

crypt

xotohop Dec 8th, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import hashlib
  2. from Crypto.Cipher import AES
  3. from Crypto.Random import get_random_bytes
  4.  
  5.  
  6. password = 'qwerty1337'
  7. key_sha256 = hashlib.sha256((password).encode('utf-8')).hexdigest()
  8.  
  9. data = b'blah blah blah'
  10. # 16, 24 or 32 bytes
  11. key_rndbytes = get_random_bytes(24)
  12. cipher = AES.new(key_rndbytes, AES.MODE_EAX) # or key_sha256
  13. ciphertext, tag = cipher.encrypt_and_digest(data)
  14.  
  15. file_out = open("encrypted.bin", "wb")
  16. [ file_out.write(x) for x in (cipher.nonce, tag, ciphertext) ]
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top