import hashlib


def aes_key(key):
    """
    Generate a valid AES key from a string.
    :param key: the key from which generate an AES key
    :return: the AES key
    """
    if isinstance(key, bytes):
        return key

    if isinstance(key, str):
        return hashlib.sha256(key.encode()).digest()
        
    raise TypeError(f"Invalid key type: {type(key)}, expect str or bytes")