def create_artifact(entity_id, message_handle, endpoint_index=0):
    """
    SAML_artifact   := B64(TypeCode EndpointIndex RemainingArtifact)
    TypeCode        := Byte1Byte2
    EndpointIndex   := Byte1Byte2

    RemainingArtifact := SourceID MessageHandle
    SourceID          := 20-byte_sequence
    MessageHandle     := 20-byte_sequence

    :param entity_id:
    :param message_handle:
    :param endpoint_index:
    :return:
    """
    if not isinstance(entity_id, six.binary_type):
        entity_id = entity_id.encode('utf-8')
    sourceid = sha1(entity_id)

    if not isinstance(message_handle, six.binary_type):
        message_handle = message_handle.encode('utf-8')
    ter = b"".join((ARTIFACT_TYPECODE,
                    ("%.2x" % endpoint_index).encode('ascii'),
                    sourceid.digest(),
                    message_handle))
    return base64.b64encode(ter).decode('ascii')