First version
This commit is contained in:
1 parent
8d73870611
commit
5b42c8328e
4 files changed
+83
No files matched your search
@@ -0,0 +1,26 @@
|
||||
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()
|
||||
Reference in new issue
Block a user