Last active
January 19, 2021 22:58
-
-
Save sojohnnysaid/a1a36586943fca7919aa8e5c1fadc24f to your computer and use it in GitHub Desktop.
encoding/decoding data in python using the cryptography, dotenv libraries
This file contains 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 | |
import json | |
import time | |
from dotenv import load_dotenv | |
from cryptography.fernet import Fernet | |
load_dotenv() | |
timestamp = time.time() | |
my_secret_key = str.encode(os.getenv('email_confirmation_secret_key')) | |
crypto = Fernet(my_secret_key) | |
user_dict_start = {'email':'john@gmail.com','first_name':'John', 'timestamp': timestamp} | |
json_bytearray = str.encode(json.dumps(user_dict_start)) | |
token = crypto.encrypt(json_bytearray) | |
crypto = Fernet(my_secret_key) | |
returned_bytearray = crypto.decrypt(token) | |
user_dict_end = json.loads(returned_bytearray.decode()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment