Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- from base64 import b64encode
- from Crypto.Cipher import AES
- from Crypto.Random import get_random_bytes
- data = b"secret"
- print(data)
- key = get_random_bytes(16)
- iv = get_random_bytes(16)
- cipher = AES.new(key, AES.MODE_CFB, iv)
- ct_bytes = cipher.encrypt(data)
- ct = b64encode(ct_bytes).decode('utf-8')
- result = json.dumps({'ciphertext':ct})
- print(result)
- cipher = AES.new(key, AES.MODE_CFB, iv)
- pt = cipher.decrypt(ct_bytes)
- rr = pt.decode("utf-8")
- print("The message was: ", rr)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement