import secrets
import base64


def generate_key(byte_length=32):
    """
    Generate cryptographically secure device key.
    """

    token_bytes = secrets.token_bytes(byte_length)
    return base64.b64encode(token_bytes).decode("utf8")