import hashlib import secrets def generate_api_key() -> tuple[str, str]: plaintext = secrets.token_urlsafe(32) hashed = hashlib.sha256(plaintext.encode()).hexdigest() return plaintext, hashed def verify_api_key(plaintext: str, hashed_key: str) -> bool: return hashlib.sha256(plaintext.encode()).hexdigest() == hashed_key