from cryptography.fernet import Fernet from simple_logger_handler import setup_logger logger = setup_logger(__name__) try: with open("/etc/secrets/encryption_key", "rb") as file: encryption_key = file.read() except FileNotFoundError: logger.fatal("[FATAL] Encryption key not found") raise except Exception as e: logger.fatal(f"[FATAL] Failed to read encryption key: {e}") raise fernet = Fernet(encryption_key) def encrypt_token(token: str) -> str: """Encrypt a token string.""" return fernet.encrypt(token.encode()).decode() def decrypt_token(token: str) -> str: """Decrypt a token string.""" return fernet.decrypt(token.encode()).decode()