18 lines
446 B
Python
18 lines
446 B
Python
|
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'))
|