Spaces:
Runtime error
Runtime error
Download backend/api/utils/encryption.py from samarthnaikk/finsight1: direct link, hf CLI and curl.
- Browser
- Download file 687 Bytes
-
https://huggingface.co/spaces/samarthnaikk/finsight1/resolve/main/backend/api/utils/encryption.py
- Command line
-
hf download hf://spaces/samarthnaikk/finsight1/backend/api/utils/encryption.py
-
curl -L -o encryption.py https://huggingface.co/spaces/samarthnaikk/finsight1/resolve/main/backend/api/utils/encryption.py
687 Bytes
| import json | |
| from cryptography.fernet import Fernet | |
| from django.conf import settings | |
| class EncryptionService: | |
| def __init__(self): | |
| key = settings.FIELD_ENCRYPTION_KEY | |
| if not key: | |
| raise ValueError("FIELD_ENCRYPTION_KEY is not set") | |
| self.cipher = Fernet(key.encode()) | |
| def encrypt(self, data: dict) -> str: | |
| json_data = json.dumps(data) | |
| encrypted = self.cipher.encrypt(json_data.encode()) | |
| return encrypted.decode() | |
| def decrypt(self, encrypted_data: str) -> dict: | |
| decrypted = self.cipher.decrypt(encrypted_data.encode()) | |
| return json.loads(decrypted.decode()) | |
| encryption_service = EncryptionService() | |