Generates a nonce (a pseudo-random token). It is seeded with the current date/time.
    :param algorithm: a string being any of the SHA hash algorithms.
    :param to_hex: a boolean describing whether we want a base64 digest or a hexadecimal digest
    :return:

def nonce(algorithm='sha1', to_hex=True):
    """
    Generates a nonce (a pseudo-random token). It is seeded with the current date/time.
    :param algorithm: a string being any of the SHA hash algorithms.
    :param to_hex: a boolean describing whether we want a base64 digest or a hexadecimal digest
    :return:
    """
    if algorithm not in _HASHES:
        return None
    result = _HASHES[algorithm](datetime.datetime.now().isoformat())
    return result.hexdigest() if to_hex else b64encode(result.digest())