You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
446 B
18 lines
446 B
import json
|
|
|
|
from cryptography.fernet import Fernet
|
|
|
|
|
|
class Auth:
|
|
|
|
def get_key(self, client_id):
|
|
return Fernet.generate_key()
|
|
|
|
def decrypt(self, cyphertext, client_id) -> dict:
|
|
return json.loads(
|
|
Fernet(self.get_key(client_id)).decrypt(cyphertext).decode())
|
|
|
|
def encrypt(self, data, client_id) -> bytes:
|
|
return Fernet(self.get_key(client_id)).encrypt(
|
|
json.dumps(data).encode('utf-8'))
|