CertificateEmbeddingOption Enumeration

Definition

Gibt den Speicherort des X.509-Zertifikats an, das zum Signieren verwendet wird.

public enum class CertificateEmbeddingOption
public enum CertificateEmbeddingOption
type CertificateEmbeddingOption = 
Public Enum CertificateEmbeddingOption
Vererbung
CertificateEmbeddingOption

Felder

InCertificatePart 0

Das Zertifikat ist in sein eigenes PackagePart eingebettet.

InSignaturePart 1

Das Zertifikat ist in dem SignaturePart eingebettet, das für die Signatur erstellt wird, die hinzugefügt wird.

NotEmbedded 2

Das Zertifikat ist nicht in das Paket eingebettet.

Beispiele

Im folgenden Beispiel wird gezeigt, wie sie verwenden CertificateEmbeddingOption , um die PackageDigitalSignatureManager.CertificateOption -Eigenschaft festzulegen.

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()

Hinweise

Wenn sich das Zertifikat im Paket befindet NotEmbedded , muss eine Anwendung, die Signaturen überprüft, eine Kopie des Zertifikats bereitstellen, um die von diesem signierten Signaturen zu überprüfen.

InSignaturePart fügt zwei Informationselemente <KeyName> und <KeyValue>als Teil des Felds der KeyInfo gespeicherten digitalen Signatur hinzu. Die <KeyName> Elemente und <KeyValue> werden nicht im Rahmen der Signaturüberprüfung verarbeitet und sind daher nicht sicher vor Änderungen. Anträge sollten keine Annahmen hinsichtlich der Gültigkeit dieser beiden Elemente treffen. Um unentdeckte Änderungen und mögliche Verwirrungen zu vermeiden, sollten Anwendungen die InCertificatePart Option anstelle von InSignaturePartverwenden. Die InCertificatePart Option bietet oder macht weder noch <KeyName><KeyValue>verfügbar.

Gilt für:

Weitere Informationen