Skip to content

Instantly share code, notes, and snippets.

@IvanIsak2000
Created January 27, 2025 15:57
Show Gist options
  • Save IvanIsak2000/c56e882b8daf7c096b631ab473add70c to your computer and use it in GitHub Desktop.
Save IvanIsak2000/c56e882b8daf7c096b631ab473add70c to your computer and use it in GitHub Desktop.
# pip install cryptography
from cryptography.fernet import Fernet
class LockBoxServer:
def __init__(self):
session_key = Fernet.generate_key()
print(f"{session_key=}")
self.fernet = Fernet(session_key)
def encrypt(self, data: bytes) -> str:
return self.fernet.encrypt(data)
def decrypt(self, token: str) -> bytes:
return self.fernet.decrypt(token)
server = LockBoxServer()
encrypt_token = server.encrypt("данные".encode())
print(f"{encrypt_token=}")
decrypt_result = server.decrypt(encrypt_token).decode()
print(f"{decrypt_result=}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment