PackageDigitalSignatureManager.Sign メソッド

定義

指定した X.509 証明書を使用して、パッケージ パーツの一覧に署名します。

オーバーロード

Sign(IEnumerable<Uri>)

X.509 証明書をユーザーに要求するプロンプトを表示します。この証明書を使用して、指定されたパッケージ パーツの一覧にデジタル署名します。

Sign(IEnumerable<Uri>, X509Certificate)

指定された X.509 証明書を使用してパッケージ パーツの一覧を署名します。

Sign(IEnumerable<Uri>, X509Certificate, IEnumerable<PackageRelationshipSelector>)

指定した X.509 証明書を使用して、パッケージ パーツとパッケージ リレーションシップの一覧に署名します。

Sign(IEnumerable<Uri>, X509Certificate, IEnumerable<PackageRelationshipSelector>, String)

特定の X.509 証明書と識別子 (ID) を使用して、パッケージ パーツとパッケージリレーションシップの一覧に署名します。

Sign(IEnumerable<Uri>, X509Certificate, IEnumerable<PackageRelationshipSelector>, String, IEnumerable<DataObject>, IEnumerable<Reference>)

指定した X.509 証明書と署名識別子 (ID) を使用して、パッケージ パーツ、パッケージ リレーションシップ、またはカスタム オブジェクトの一覧に署名します。

次の例は、 内のパーツの一覧にデジタル署名する手順を Package示しています。 完全なサンプルについては、「 デジタル署名サンプルを使用したパッケージの作成」を参照してください。

private static void SignAllParts(Package package)
{
    if (package == null)
        throw new ArgumentNullException("SignAllParts(package)");

    // Create the DigitalSignature Manager
    PackageDigitalSignatureManager dsm =
        new PackageDigitalSignatureManager(package);
    dsm.CertificateOption =
        CertificateEmbeddingOption.InSignaturePart;

    // Create a list of all the part URIs in the package to sign
    // (GetParts() also includes PackageRelationship parts).
    System.Collections.Generic.List<Uri> toSign =
        new System.Collections.Generic.List<Uri>();
    foreach (PackagePart packagePart in package.GetParts())
    {
        // Add all package parts to the list for signing.
        toSign.Add(packagePart.Uri);
    }

    // Add the URI for SignatureOrigin PackageRelationship part.
    // The SignatureOrigin relationship is created when Sign() is called.
    // Signing the SignatureOrigin relationship disables counter-signatures.
    toSign.Add(PackUriHelper.GetRelationshipPartUri(dsm.SignatureOrigin));

    // Also sign the SignatureOrigin part.
    toSign.Add(dsm.SignatureOrigin);

    // Add the package relationship to the signature origin to be signed.
    toSign.Add(PackUriHelper.GetRelationshipPartUri(new Uri("/", UriKind.RelativeOrAbsolute)));

    // Sign() will prompt the user to select a Certificate to sign with.
    try
    {
        dsm.Sign(toSign);
    }

    // If there are no certificates or the SmartCard manager is
    // not running, catch the exception and show an error message.
    catch (CryptographicException ex)
    {
        MessageBox.Show(
            "Cannot Sign\n" + ex.Message,
            "No Digital Certificates Available",
            MessageBoxButton.OK,
            MessageBoxImage.Exclamation);
    }
}// end:SignAllParts()
Private Shared Sub SignAllParts(ByVal package As Package)
    If package Is Nothing Then
        Throw New ArgumentNullException("SignAllParts(package)")
    End If

    ' Create the DigitalSignature Manager
    Dim dsm As New PackageDigitalSignatureManager(package)
    dsm.CertificateOption = CertificateEmbeddingOption.InSignaturePart

    ' Create a list of all the part URIs in the package to sign
    ' (GetParts() also includes PackageRelationship parts).
    Dim toSign As New System.Collections.Generic.List(Of Uri)()
    For Each packagePart As PackagePart In package.GetParts()
        ' Add all package parts to the list for signing.
        toSign.Add(packagePart.Uri)
    Next

    ' Add the URI for SignatureOrigin PackageRelationship part.
    ' The SignatureOrigin relationship is created when Sign() is called.
    ' Signing the SignatureOrigin relationship disables counter-signatures.
    toSign.Add(PackUriHelper.GetRelationshipPartUri(dsm.SignatureOrigin))

    ' Also sign the SignatureOrigin part.
    toSign.Add(dsm.SignatureOrigin)

    ' Add the package relationship to the signature origin to be signed.
    toSign.Add(PackUriHelper.GetRelationshipPartUri(New Uri("/", UriKind.RelativeOrAbsolute)))

    ' Sign() will prompt the user to select a Certificate to sign with.
    Try
        dsm.Sign(toSign)
    Catch ex As CryptographicException

        ' If there are no certificates or the SmartCard manager is
        ' not running, catch the exception and show an error message.
        MessageBox.Show("Cannot Sign" & vbLf & ex.Message, "No Digital Certificates Available", MessageBoxButton.OK, MessageBoxImage.Exclamation)

    End Try
End Sub
Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, ByVal value As T) As T
    target = value
    Return value
End Function
' end:SignAllParts()

Sign(IEnumerable<Uri>)

X.509 証明書をユーザーに要求するプロンプトを表示します。この証明書を使用して、指定されたパッケージ パーツの一覧にデジタル署名します。

public:
 System::IO::Packaging::PackageDigitalSignature ^ Sign(System::Collections::Generic::IEnumerable<Uri ^> ^ parts);
public System.IO.Packaging.PackageDigitalSignature Sign (System.Collections.Generic.IEnumerable<Uri> parts);
member this.Sign : seq<Uri> -> System.IO.Packaging.PackageDigitalSignature
Public Function Sign (parts As IEnumerable(Of Uri)) As PackageDigitalSignature

パラメーター

parts
IEnumerable<Uri>

署名する PackagePart 要素の Uniform Resource Identifier (URI) の一覧。

戻り値

parts の一覧の署名に使用するデジタル署名。

次の例は、パッケージ パーツの一覧にデジタル署名する方法を示しています。 完全なサンプルについては、 デジタル署名を使用したパッケージの作成に関するサンプルを参照してください。

private static void SignAllParts(Package package)
{
    if (package == null)
        throw new ArgumentNullException("SignAllParts(package)");

    // Create the DigitalSignature Manager
    PackageDigitalSignatureManager dsm =
        new PackageDigitalSignatureManager(package);
    dsm.CertificateOption =
        CertificateEmbeddingOption.InSignaturePart;

    // Create a list of all the part URIs in the package to sign
    // (GetParts() also includes PackageRelationship parts).
    System.Collections.Generic.List<Uri> toSign =
        new System.Collections.Generic.List<Uri>();
    foreach (PackagePart packagePart in package.GetParts())
    {
        // Add all package parts to the list for signing.
        toSign.Add(packagePart.Uri);
    }

    // Add the URI for SignatureOrigin PackageRelationship part.
    // The SignatureOrigin relationship is created when Sign() is called.
    // Signing the SignatureOrigin relationship disables counter-signatures.
    toSign.Add(PackUriHelper.GetRelationshipPartUri(dsm.SignatureOrigin));

    // Also sign the SignatureOrigin part.
    toSign.Add(dsm.SignatureOrigin);

    // Add the package relationship to the signature origin to be signed.
    toSign.Add(PackUriHelper.GetRelationshipPartUri(new Uri("/", UriKind.RelativeOrAbsolute)));

    // Sign() will prompt the user to select a Certificate to sign with.
    try
    {
        dsm.Sign(toSign);
    }

    // If there are no certificates or the SmartCard manager is
    // not running, catch the exception and show an error message.
    catch (CryptographicException ex)
    {
        MessageBox.Show(
            "Cannot Sign\n" + ex.Message,
            "No Digital Certificates Available",
            MessageBoxButton.OK,
            MessageBoxImage.Exclamation);
    }
}// end:SignAllParts()
Private Shared Sub SignAllParts(ByVal package As Package)
    If package Is Nothing Then
        Throw New ArgumentNullException("SignAllParts(package)")
    End If

    ' Create the DigitalSignature Manager
    Dim dsm As New PackageDigitalSignatureManager(package)
    dsm.CertificateOption = CertificateEmbeddingOption.InSignaturePart

    ' Create a list of all the part URIs in the package to sign
    ' (GetParts() also includes PackageRelationship parts).
    Dim toSign As New System.Collections.Generic.List(Of Uri)()
    For Each packagePart As PackagePart In package.GetParts()
        ' Add all package parts to the list for signing.
        toSign.Add(packagePart.Uri)
    Next

    ' Add the URI for SignatureOrigin PackageRelationship part.
    ' The SignatureOrigin relationship is created when Sign() is called.
    ' Signing the SignatureOrigin relationship disables counter-signatures.
    toSign.Add(PackUriHelper.GetRelationshipPartUri(dsm.SignatureOrigin))

    ' Also sign the SignatureOrigin part.
    toSign.Add(dsm.SignatureOrigin)

    ' Add the package relationship to the signature origin to be signed.
    toSign.Add(PackUriHelper.GetRelationshipPartUri(New Uri("/", UriKind.RelativeOrAbsolute)))

    ' Sign() will prompt the user to select a Certificate to sign with.
    Try
        dsm.Sign(toSign)
    Catch ex As CryptographicException

        ' If there are no certificates or the SmartCard manager is
        ' not running, catch the exception and show an error message.
        MessageBox.Show("Cannot Sign" & vbLf & ex.Message, "No Digital Certificates Available", MessageBoxButton.OK, MessageBoxImage.Exclamation)

    End Try
End Sub
Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, ByVal value As T) As T
    target = value
    Return value
End Function
' end:SignAllParts()

注釈

証明書の選択ダイアログを特定のウィンドウにモーダルにするには、 を呼び出すSign前に プロパティをParentWindow設定します。

Sign 既定の証明書ストアに証明書がない場合、証明書の入力を求めるメッセージは表示されません。

適用対象

Sign(IEnumerable<Uri>, X509Certificate)

指定された X.509 証明書を使用してパッケージ パーツの一覧を署名します。

public:
 System::IO::Packaging::PackageDigitalSignature ^ Sign(System::Collections::Generic::IEnumerable<Uri ^> ^ parts, System::Security::Cryptography::X509Certificates::X509Certificate ^ certificate);
public System.IO.Packaging.PackageDigitalSignature Sign (System.Collections.Generic.IEnumerable<Uri> parts, System.Security.Cryptography.X509Certificates.X509Certificate certificate);
member this.Sign : seq<Uri> * System.Security.Cryptography.X509Certificates.X509Certificate -> System.IO.Packaging.PackageDigitalSignature
Public Function Sign (parts As IEnumerable(Of Uri), certificate As X509Certificate) As PackageDigitalSignature

パラメーター

parts
IEnumerable<Uri>

署名する PackagePart 要素の Uniform Resource Identifier (URI) の一覧。

certificate
X509Certificate

指定された parts のそれぞれにデジタル署名するために使用する X.509 証明書。

戻り値

parts の指定された一覧に署名するために使用されるデジタル署名、または、証明書が見つからなかった場合や証明書の選択ダイアログ ボックスでユーザーが [キャンセル] をクリックした場合は null

次の例は、 内のパーツの一覧にデジタル署名する方法を Package示しています。 完全な例については、 デジタル署名を使用したパッケージの作成に関するサンプルを参照してください。

private static void SignAllParts(Package package)
{
    if (package == null)
        throw new ArgumentNullException("SignAllParts(package)");

    // Create the DigitalSignature Manager
    PackageDigitalSignatureManager dsm =
        new PackageDigitalSignatureManager(package);
    dsm.CertificateOption =
        CertificateEmbeddingOption.InSignaturePart;

    // Create a list of all the part URIs in the package to sign
    // (GetParts() also includes PackageRelationship parts).
    System.Collections.Generic.List<Uri> toSign =
        new System.Collections.Generic.List<Uri>();
    foreach (PackagePart packagePart in package.GetParts())
    {
        // Add all package parts to the list for signing.
        toSign.Add(packagePart.Uri);
    }

    // Add the URI for SignatureOrigin PackageRelationship part.
    // The SignatureOrigin relationship is created when Sign() is called.
    // Signing the SignatureOrigin relationship disables counter-signatures.
    toSign.Add(PackUriHelper.GetRelationshipPartUri(dsm.SignatureOrigin));

    // Also sign the SignatureOrigin part.
    toSign.Add(dsm.SignatureOrigin);

    // Add the package relationship to the signature origin to be signed.
    toSign.Add(PackUriHelper.GetRelationshipPartUri(new Uri("/", UriKind.RelativeOrAbsolute)));

    // Sign() will prompt the user to select a Certificate to sign with.
    try
    {
        dsm.Sign(toSign);
    }

    // If there are no certificates or the SmartCard manager is
    // not running, catch the exception and show an error message.
    catch (CryptographicException ex)
    {
        MessageBox.Show(
            "Cannot Sign\n" + ex.Message,
            "No Digital Certificates Available",
            MessageBoxButton.OK,
            MessageBoxImage.Exclamation);
    }
}// end:SignAllParts()
Private Shared Sub SignAllParts(ByVal package As Package)
    If package Is Nothing Then
        Throw New ArgumentNullException("SignAllParts(package)")
    End If

    ' Create the DigitalSignature Manager
    Dim dsm As New PackageDigitalSignatureManager(package)
    dsm.CertificateOption = CertificateEmbeddingOption.InSignaturePart

    ' Create a list of all the part URIs in the package to sign
    ' (GetParts() also includes PackageRelationship parts).
    Dim toSign As New System.Collections.Generic.List(Of Uri)()
    For Each packagePart As PackagePart In package.GetParts()
        ' Add all package parts to the list for signing.
        toSign.Add(packagePart.Uri)
    Next

    ' Add the URI for SignatureOrigin PackageRelationship part.
    ' The SignatureOrigin relationship is created when Sign() is called.
    ' Signing the SignatureOrigin relationship disables counter-signatures.
    toSign.Add(PackUriHelper.GetRelationshipPartUri(dsm.SignatureOrigin))

    ' Also sign the SignatureOrigin part.
    toSign.Add(dsm.SignatureOrigin)

    ' Add the package relationship to the signature origin to be signed.
    toSign.Add(PackUriHelper.GetRelationshipPartUri(New Uri("/", UriKind.RelativeOrAbsolute)))

    ' Sign() will prompt the user to select a Certificate to sign with.
    Try
        dsm.Sign(toSign)
    Catch ex As CryptographicException

        ' If there are no certificates or the SmartCard manager is
        ' not running, catch the exception and show an error message.
        MessageBox.Show("Cannot Sign" & vbLf & ex.Message, "No Digital Certificates Available", MessageBoxButton.OK, MessageBoxImage.Exclamation)

    End Try
End Sub
Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, ByVal value As T) As T
    target = value
    Return value
End Function
' end:SignAllParts()

適用対象

Sign(IEnumerable<Uri>, X509Certificate, IEnumerable<PackageRelationshipSelector>)

指定した X.509 証明書を使用して、パッケージ パーツとパッケージ リレーションシップの一覧に署名します。

public:
 System::IO::Packaging::PackageDigitalSignature ^ Sign(System::Collections::Generic::IEnumerable<Uri ^> ^ parts, System::Security::Cryptography::X509Certificates::X509Certificate ^ certificate, System::Collections::Generic::IEnumerable<System::IO::Packaging::PackageRelationshipSelector ^> ^ relationshipSelectors);
public System.IO.Packaging.PackageDigitalSignature Sign (System.Collections.Generic.IEnumerable<Uri> parts, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Collections.Generic.IEnumerable<System.IO.Packaging.PackageRelationshipSelector> relationshipSelectors);
member this.Sign : seq<Uri> * System.Security.Cryptography.X509Certificates.X509Certificate * seq<System.IO.Packaging.PackageRelationshipSelector> -> System.IO.Packaging.PackageDigitalSignature
Public Function Sign (parts As IEnumerable(Of Uri), certificate As X509Certificate, relationshipSelectors As IEnumerable(Of PackageRelationshipSelector)) As PackageDigitalSignature

パラメーター

parts
IEnumerable<Uri>

署名する PackagePart オブジェクトの Uniform Resource Identifier (URI) の一覧。

certificate
X509Certificate

指定したパーツおよびリレーションシップのそれぞれにデジタル署名するために使用する X.509 証明書。

relationshipSelectors
IEnumerable<PackageRelationshipSelector>

署名する PackageRelationship オブジェクトの一覧。

戻り値

parts および relationshipSelectors の一覧で指定されている要素の署名に使用するデジタル署名。

例外

parts でも relationshipSelectors でも、署名するオブジェクトが指定されていません。

次の例は、パッケージ パーツの一覧にデジタル署名する方法を示しています。 完全なサンプルについては、 デジタル署名を使用したパッケージの作成に関するサンプルを参照してください。

private static void SignAllParts(Package package)
{
    if (package == null)
        throw new ArgumentNullException("SignAllParts(package)");

    // Create the DigitalSignature Manager
    PackageDigitalSignatureManager dsm =
        new PackageDigitalSignatureManager(package);
    dsm.CertificateOption =
        CertificateEmbeddingOption.InSignaturePart;

    // Create a list of all the part URIs in the package to sign
    // (GetParts() also includes PackageRelationship parts).
    System.Collections.Generic.List<Uri> toSign =
        new System.Collections.Generic.List<Uri>();
    foreach (PackagePart packagePart in package.GetParts())
    {
        // Add all package parts to the list for signing.
        toSign.Add(packagePart.Uri);
    }

    // Add the URI for SignatureOrigin PackageRelationship part.
    // The SignatureOrigin relationship is created when Sign() is called.
    // Signing the SignatureOrigin relationship disables counter-signatures.
    toSign.Add(PackUriHelper.GetRelationshipPartUri(dsm.SignatureOrigin));

    // Also sign the SignatureOrigin part.
    toSign.Add(dsm.SignatureOrigin);

    // Add the package relationship to the signature origin to be signed.
    toSign.Add(PackUriHelper.GetRelationshipPartUri(new Uri("/", UriKind.RelativeOrAbsolute)));

    // Sign() will prompt the user to select a Certificate to sign with.
    try
    {
        dsm.Sign(toSign);
    }

    // If there are no certificates or the SmartCard manager is
    // not running, catch the exception and show an error message.
    catch (CryptographicException ex)
    {
        MessageBox.Show(
            "Cannot Sign\n" + ex.Message,
            "No Digital Certificates Available",
            MessageBoxButton.OK,
            MessageBoxImage.Exclamation);
    }
}// end:SignAllParts()
Private Shared Sub SignAllParts(ByVal package As Package)
    If package Is Nothing Then
        Throw New ArgumentNullException("SignAllParts(package)")
    End If

    ' Create the DigitalSignature Manager
    Dim dsm As New PackageDigitalSignatureManager(package)
    dsm.CertificateOption = CertificateEmbeddingOption.InSignaturePart

    ' Create a list of all the part URIs in the package to sign
    ' (GetParts() also includes PackageRelationship parts).
    Dim toSign As New System.Collections.Generic.List(Of Uri)()
    For Each packagePart As PackagePart In package.GetParts()
        ' Add all package parts to the list for signing.
        toSign.Add(packagePart.Uri)
    Next

    ' Add the URI for SignatureOrigin PackageRelationship part.
    ' The SignatureOrigin relationship is created when Sign() is called.
    ' Signing the SignatureOrigin relationship disables counter-signatures.
    toSign.Add(PackUriHelper.GetRelationshipPartUri(dsm.SignatureOrigin))

    ' Also sign the SignatureOrigin part.
    toSign.Add(dsm.SignatureOrigin)

    ' Add the package relationship to the signature origin to be signed.
    toSign.Add(PackUriHelper.GetRelationshipPartUri(New Uri("/", UriKind.RelativeOrAbsolute)))

    ' Sign() will prompt the user to select a Certificate to sign with.
    Try
        dsm.Sign(toSign)
    Catch ex As CryptographicException

        ' If there are no certificates or the SmartCard manager is
        ' not running, catch the exception and show an error message.
        MessageBox.Show("Cannot Sign" & vbLf & ex.Message, "No Digital Certificates Available", MessageBoxButton.OK, MessageBoxImage.Exclamation)

    End Try
End Sub
Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, ByVal value As T) As T
    target = value
    Return value
End Function
' end:SignAllParts()

注釈

と のrelationshipSelectorspartsには、署名する要素が少なくとも 1 つ必要です。

適用対象

Sign(IEnumerable<Uri>, X509Certificate, IEnumerable<PackageRelationshipSelector>, String)

特定の X.509 証明書と識別子 (ID) を使用して、パッケージ パーツとパッケージリレーションシップの一覧に署名します。

public:
 System::IO::Packaging::PackageDigitalSignature ^ Sign(System::Collections::Generic::IEnumerable<Uri ^> ^ parts, System::Security::Cryptography::X509Certificates::X509Certificate ^ certificate, System::Collections::Generic::IEnumerable<System::IO::Packaging::PackageRelationshipSelector ^> ^ relationshipSelectors, System::String ^ signatureId);
public System.IO.Packaging.PackageDigitalSignature Sign (System.Collections.Generic.IEnumerable<Uri> parts, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Collections.Generic.IEnumerable<System.IO.Packaging.PackageRelationshipSelector> relationshipSelectors, string signatureId);
member this.Sign : seq<Uri> * System.Security.Cryptography.X509Certificates.X509Certificate * seq<System.IO.Packaging.PackageRelationshipSelector> * string -> System.IO.Packaging.PackageDigitalSignature
Public Function Sign (parts As IEnumerable(Of Uri), certificate As X509Certificate, relationshipSelectors As IEnumerable(Of PackageRelationshipSelector), signatureId As String) As PackageDigitalSignature

パラメーター

parts
IEnumerable<Uri>

署名する PackagePart オブジェクトの Uniform Resource Identifier (URI) の一覧。

certificate
X509Certificate

指定したパーツおよびリレーションシップのそれぞれにデジタル署名するために使用する X.509 証明書。

relationshipSelectors
IEnumerable<PackageRelationshipSelector>

署名する PackageRelationship オブジェクトの一覧。

signatureId
String

署名に関連付ける識別文字列。

戻り値

parts および relationshipSelectors の一覧で指定されている要素の署名に使用するデジタル署名。

例外

partsrelationshipSelectors のいずれによっても、署名する要素は指定されません。

次の例は、パッケージ パーツの一覧にデジタル署名する方法を示しています。 完全なサンプルについては、 デジタル署名を使用したパッケージの作成に関するサンプルを参照してください。

private static void SignAllParts(Package package)
{
    if (package == null)
        throw new ArgumentNullException("SignAllParts(package)");

    // Create the DigitalSignature Manager
    PackageDigitalSignatureManager dsm =
        new PackageDigitalSignatureManager(package);
    dsm.CertificateOption =
        CertificateEmbeddingOption.InSignaturePart;

    // Create a list of all the part URIs in the package to sign
    // (GetParts() also includes PackageRelationship parts).
    System.Collections.Generic.List<Uri> toSign =
        new System.Collections.Generic.List<Uri>();
    foreach (PackagePart packagePart in package.GetParts())
    {
        // Add all package parts to the list for signing.
        toSign.Add(packagePart.Uri);
    }

    // Add the URI for SignatureOrigin PackageRelationship part.
    // The SignatureOrigin relationship is created when Sign() is called.
    // Signing the SignatureOrigin relationship disables counter-signatures.
    toSign.Add(PackUriHelper.GetRelationshipPartUri(dsm.SignatureOrigin));

    // Also sign the SignatureOrigin part.
    toSign.Add(dsm.SignatureOrigin);

    // Add the package relationship to the signature origin to be signed.
    toSign.Add(PackUriHelper.GetRelationshipPartUri(new Uri("/", UriKind.RelativeOrAbsolute)));

    // Sign() will prompt the user to select a Certificate to sign with.
    try
    {
        dsm.Sign(toSign);
    }

    // If there are no certificates or the SmartCard manager is
    // not running, catch the exception and show an error message.
    catch (CryptographicException ex)
    {
        MessageBox.Show(
            "Cannot Sign\n" + ex.Message,
            "No Digital Certificates Available",
            MessageBoxButton.OK,
            MessageBoxImage.Exclamation);
    }
}// end:SignAllParts()
Private Shared Sub SignAllParts(ByVal package As Package)
    If package Is Nothing Then
        Throw New ArgumentNullException("SignAllParts(package)")
    End If

    ' Create the DigitalSignature Manager
    Dim dsm As New PackageDigitalSignatureManager(package)
    dsm.CertificateOption = CertificateEmbeddingOption.InSignaturePart

    ' Create a list of all the part URIs in the package to sign
    ' (GetParts() also includes PackageRelationship parts).
    Dim toSign As New System.Collections.Generic.List(Of Uri)()
    For Each packagePart As PackagePart In package.GetParts()
        ' Add all package parts to the list for signing.
        toSign.Add(packagePart.Uri)
    Next

    ' Add the URI for SignatureOrigin PackageRelationship part.
    ' The SignatureOrigin relationship is created when Sign() is called.
    ' Signing the SignatureOrigin relationship disables counter-signatures.
    toSign.Add(PackUriHelper.GetRelationshipPartUri(dsm.SignatureOrigin))

    ' Also sign the SignatureOrigin part.
    toSign.Add(dsm.SignatureOrigin)

    ' Add the package relationship to the signature origin to be signed.
    toSign.Add(PackUriHelper.GetRelationshipPartUri(New Uri("/", UriKind.RelativeOrAbsolute)))

    ' Sign() will prompt the user to select a Certificate to sign with.
    Try
        dsm.Sign(toSign)
    Catch ex As CryptographicException

        ' If there are no certificates or the SmartCard manager is
        ' not running, catch the exception and show an error message.
        MessageBox.Show("Cannot Sign" & vbLf & ex.Message, "No Digital Certificates Available", MessageBoxButton.OK, MessageBoxImage.Exclamation)

    End Try
End Sub
Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, ByVal value As T) As T
    target = value
    Return value
End Function
' end:SignAllParts()

注釈

リストは partsnull にすることも、少なくとも 1 つのエントリが含まれている場合 relationshipSelectors もかまいません。

リストは relationshipSelectorsnull にすることも、少なくとも 1 つのエントリが含まれている場合 parts もかまいません。

リストと の parts 間には、 relationshipSelectors 署名する要素が少なくとも 1 つ必要です。

適用対象

Sign(IEnumerable<Uri>, X509Certificate, IEnumerable<PackageRelationshipSelector>, String, IEnumerable<DataObject>, IEnumerable<Reference>)

指定した X.509 証明書と署名識別子 (ID) を使用して、パッケージ パーツ、パッケージ リレーションシップ、またはカスタム オブジェクトの一覧に署名します。

public:
 System::IO::Packaging::PackageDigitalSignature ^ Sign(System::Collections::Generic::IEnumerable<Uri ^> ^ parts, System::Security::Cryptography::X509Certificates::X509Certificate ^ certificate, System::Collections::Generic::IEnumerable<System::IO::Packaging::PackageRelationshipSelector ^> ^ relationshipSelectors, System::String ^ signatureId, System::Collections::Generic::IEnumerable<System::Security::Cryptography::Xml::DataObject ^> ^ signatureObjects, System::Collections::Generic::IEnumerable<System::Security::Cryptography::Xml::Reference ^> ^ objectReferences);
[System.Security.SecurityCritical]
public System.IO.Packaging.PackageDigitalSignature Sign (System.Collections.Generic.IEnumerable<Uri> parts, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Collections.Generic.IEnumerable<System.IO.Packaging.PackageRelationshipSelector> relationshipSelectors, string signatureId, System.Collections.Generic.IEnumerable<System.Security.Cryptography.Xml.DataObject> signatureObjects, System.Collections.Generic.IEnumerable<System.Security.Cryptography.Xml.Reference> objectReferences);
public System.IO.Packaging.PackageDigitalSignature Sign (System.Collections.Generic.IEnumerable<Uri> parts, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Collections.Generic.IEnumerable<System.IO.Packaging.PackageRelationshipSelector> relationshipSelectors, string signatureId, System.Collections.Generic.IEnumerable<System.Security.Cryptography.Xml.DataObject> signatureObjects, System.Collections.Generic.IEnumerable<System.Security.Cryptography.Xml.Reference> objectReferences);
[<System.Security.SecurityCritical>]
member this.Sign : seq<Uri> * System.Security.Cryptography.X509Certificates.X509Certificate * seq<System.IO.Packaging.PackageRelationshipSelector> * string * seq<System.Security.Cryptography.Xml.DataObject> * seq<System.Security.Cryptography.Xml.Reference> -> System.IO.Packaging.PackageDigitalSignature
member this.Sign : seq<Uri> * System.Security.Cryptography.X509Certificates.X509Certificate * seq<System.IO.Packaging.PackageRelationshipSelector> * string * seq<System.Security.Cryptography.Xml.DataObject> * seq<System.Security.Cryptography.Xml.Reference> -> System.IO.Packaging.PackageDigitalSignature
Public Function Sign (parts As IEnumerable(Of Uri), certificate As X509Certificate, relationshipSelectors As IEnumerable(Of PackageRelationshipSelector), signatureId As String, signatureObjects As IEnumerable(Of DataObject), objectReferences As IEnumerable(Of Reference)) As PackageDigitalSignature

パラメーター

parts
IEnumerable<Uri>

署名する PackagePart オブジェクトの Uniform Resource Identifier (URI) の一覧。

certificate
X509Certificate

指定したパーツおよびリレーションシップのそれぞれにデジタル署名するために使用する X.509 証明書。

relationshipSelectors
IEnumerable<PackageRelationshipSelector>

署名する PackageRelationship オブジェクトの一覧。

signatureId
String

署名に関連付ける識別文字列。

signatureObjects
IEnumerable<DataObject>

署名するカスタム データ オブジェクトの一覧。

objectReferences
IEnumerable<Reference>

署名するカスタム オブジェクトへの参照の一覧。

戻り値

parts および relationshipSelectors の一覧で指定されている要素の署名に使用するデジタル署名。

属性

例外

partsrelationshipSelectorssignatureObjects、および objectReferences のいずれによっても、署名する要素は指定されません。

署名されているパーツの ContentType が空、null、または定義されていない TransformMapping を参照しています。

signatureId は ではなく null 、有効な XML スキーマ ID ではありません (たとえば、先頭の数字で始まります)。

注釈

、、または objectReferencesにサインインsignatureObjectspartsrelationshipSelectorsするには、少なくとも 1 つの要素が必要です。

注意

、、Manifest、および という用語Objectは、次の 2 つの注釈で、W3C XML-Signature 構文と処理の仕様で定義されている要素の型とタグを参照してくださいhttps://www.w3.org/TR/xmldsig-core/TransformSignaturePropertiesReference

このメソッドおよび他Signのメソッド オーバーロードでは、パッケージ パーツ ContentTypeに基づいて 適用する をTransform定義する現在TransformMappingのディクショナリが使用されます。 現在、Microsoft Open Packaging Conventions (OPC) 仕様では、有効な Transform アルゴリズムは C14 と C14N の 2 つだけです。 W3C XML-Signature 構文および処理標準では、空 Manifest のタグは使用できません。 また、Open Packaging Conventions 仕様には、 タグと SignatureProperties タグの両方ManifestPackage含む固有Objectのタグが必要です。 各 Manifest タグには、少なくとも 1 つの Reference タグも含まれます。 これらのタグでは、署名が または にのみ必要な場合でも、各署名で少なくとも 1 つの PackagePart (空でない部分タグ) または PackageRelationship (空relationshipSelectorsでない) 署名signatureObjectsobjectReferencesが必要です。

このメソッドは Sign 、 で定義されている DigestMethod それぞれに Reference 関連付けられているプロパティを objectReferences無視します。

この Sign オーバーロードは、カスタム Object タグを必要とする XML 署名の生成をサポートします。 指定された Object タグに署名するには、対応する Reference タグに、ローカル フラグメント構文のタグを指定する URI (Uniform Resource Identifier) を指定 Object する必要があります。 たとえば、タグの Object ID が "myObject" の場合、タグ内の Reference URI は "#myObject" になります。 符号なしオブジェクトの場合は、不要 Reference です。

適用対象