| 123456789101112131415161718 |
- import hashlib
- import secrets
- API_KEY_PREFIX = "agp"
- def generate_api_key() -> str:
- return f"{API_KEY_PREFIX}_{secrets.token_urlsafe(32)}"
- def hash_api_key(api_key: str) -> str:
- return hashlib.sha256(api_key.encode("utf-8")).hexdigest()
- def get_api_key_prefix(api_key: str) -> str:
- if len(api_key) <= 12:
- return api_key
- return api_key[:12]
|