Created
January 27, 2025 15:57
-
-
Save IvanIsak2000/c56e882b8daf7c096b631ab473add70c to your computer and use it in GitHub Desktop.
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
# 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