CertificateEmbeddingOption Enumeración

Definición

Especifica la ubicación donde se almacena el certificado X.509 que se usa en la firma.Specifies the location where the X.509 certificate that is used in signing is stored.

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

Campos

InCertificatePart 0

El certificado se inserta en su propia PackagePart.The certificate is embedded in its own PackagePart.

InSignaturePart 1

El certificado se inserta en la SignaturePart que se crea para la signatura que se está agregando.The certificate is embedded in the SignaturePart that is created for the signature being added.

NotEmbedded 2

El certificado no está insertado en el paquete.The certificate in not embedded in the package.

Ejemplos

En el ejemplo siguiente se muestra cómo CertificateEmbeddingOption usar para establecer la PackageDigitalSignatureManager.CertificateOption propiedad.The following example shows how to use CertificateEmbeddingOption in order to set the PackageDigitalSignatureManager.CertificateOption property.

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

Comentarios

Si el certificado está NotEmbedded en el paquete, una aplicación que comprueba las firmas debe proporcionar una copia del certificado para comprobar las firmas firmadas por él.If the certificate is NotEmbedded in the package, an application that verifies signatures must provide a copy of the certificate in order to verify the signatures that are signed by it.

InSignaturePartagrega dos elementos informativos <KeyName> , <KeyValue>y KeyInfo , como parte del campo de la firma digital almacenada.InSignaturePart adds two informational elements, <KeyName> and <KeyValue>, as part of the KeyInfo field of the stored digital signature. Los <KeyName> elementos <KeyValue> y no se procesan como parte de la validación de la firma y, por lo tanto, no se protegen de la modificación.The <KeyName> and <KeyValue> elements are not processed as part of signature validation and are therefore not secure from modification. Las aplicaciones no deben suponer ninguna suposición con respecto a la validez de estos dos elementos.Applications should not make any assumption regarding the validity of these two elements. Para evitar la modificación no detectada y la posible confusión, las InCertificatePart aplicaciones deben usar la InSignaturePartopción en lugar de.To avoid undetected modification and possible confusion, applications should use the InCertificatePart option instead of InSignaturePart. La InCertificatePart opción no proporciona ni <KeyName> expone ni <KeyValue>.The InCertificatePart option does not provide or expose either <KeyName> or <KeyValue>.

Se aplica a

Consulte también: