def METHOD_NAME(password: str, key: str, hash_algorithm: str = None, key_id: str = None) -> str:
    """
    Encrypt a password for Message Digest Keys
    <key> should be the interface name e.g. "Ethernet1"
    <hash_algorithm>  MUST be in  ["md5", "sha1", "sha256", "sha384", "sha512"]
    <key_id> MUST be set
    The key is transformed to either:: <key>_<hash_algorithm>Key_<key_id> for message digest keys
    Returns the encrypted password as a string
    """
    _validate_password_and_key(password, key)
    if hash_algorithm is None or key_id is None:
        raise AristaAvdMissingVariableError("For OSPF message digest keys, both hash_algorithm and key_id are required")
    if hash_algorithm not in OSPF_MESSAGE_DIGEST_HASH_ALGORITHMS:
        raise AristaAvdError(f"For OSPF message digest keys, `hash_algorithm` must be in {OSPF_MESSAGE_DIGEST_HASH_ALGORITHMS}")
    data = bytes(password, encoding="UTF-8")
    key_b = bytes(f"{key}_{hash_algorithm}Key_{key_id}", encoding="UTF-8")
    return cbc_encrypt(key_b, data).decode()