Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. import json
  2. from base64 import b64encode
  3. from Crypto.Cipher import AES
  4. from Crypto.Random import get_random_bytes
  5.  
  6. data = b"secret"
  7. print(data)
  8. key = get_random_bytes(16)
  9. iv = get_random_bytes(16)
  10. cipher = AES.new(key, AES.MODE_CFB, iv)
  11. ct_bytes = cipher.encrypt(data)
  12. ct = b64encode(ct_bytes).decode('utf-8')
  13. result = json.dumps({'ciphertext':ct})
  14. print(result)
  15.  
  16.  
  17. cipher = AES.new(key, AES.MODE_CFB, iv)
  18. pt = cipher.decrypt(ct_bytes)
  19. rr = pt.decode("utf-8")
  20. print("The message was: ", rr)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement