import base64
import secrets


def generate_byte_string(length: int = 32) -> bytes:
    """Create a base64-encoded random byte string containing *nbytes* bytes

    Example output:

        b'RQWLR1FETAc7aKTyY11TUloY4ZMN9NCMbalu136UaJ0='

    :param length: int length in bytes
    :return: bytes random byte string
    """

    return base64.urlsafe_b64encode(secrets.token_bytes(length))