import hashlib from cryptography.hazmat.primitives.ciphers.aead import AESGCM import secrets def encrypt_file(file_data:bytes,jwt_token:str): key = hashlib.sha256(jwt_token.encode("utf-8")).digest() aes = AESGCM(key) nonce = secrets.token_bytes(12) encrypted = aes.encrypt(nonce, file_data, None) return encrypted with open("fc43dab7-394f-4142-bb04-b003fb2ceb50.room", "rb") as f: file_data = f.read() encrypted_file = encrypt_file(file_data, "user_jwt") with open("fc43dab7-394f-4142-bb04-b003fb2ceb50.room.ecrypted", "wb") as f: f.write(encrypted_file)