21 lines
511 B
Python
21 lines
511 B
Python
import logging
|
|
from os import getenv
|
|
|
|
from cryptography.fernet import Fernet
|
|
|
|
from secret_manager import get_secret
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
encryption_key = get_secret(getenv("ENCRYPTION_KEY",""),"/etc/secrets/encryption_key")
|
|
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() |