sendio/backend/app/utils/encryption.py
2026-01-13 05:17:57 +02:00

19 lines
649 B
Python

from cryptography.fernet import Fernet
from app.core.config import settings
def get_cipher():
"""Get Fernet cipher for encryption/decryption"""
if not settings.GOOGLE_TOKEN_ENCRYPTION_KEY:
raise ValueError("GOOGLE_TOKEN_ENCRYPTION_KEY not set")
return Fernet(settings.GOOGLE_TOKEN_ENCRYPTION_KEY.encode())
def encrypt_token(token: str) -> str:
"""Encrypt a token string"""
cipher = get_cipher()
return cipher.encrypt(token.encode()).decode()
def decrypt_token(encrypted_token: str) -> str:
"""Decrypt an encrypted token"""
cipher = get_cipher()
return cipher.decrypt(encrypted_token.encode()).decode()