XpsDocument.SignDigitally Método

Definição

Assina uma coleção de partes do pacote usando um certificado X.509 especificado.Signs a collection of package parts by using a specified X.509 certificate.

Sobrecargas

SignDigitally(X509Certificate, Boolean, XpsDigSigPartAlteringRestrictions)

Assina uma coleção de partes do pacote com um certificado X.509 especificado.Signs a collection of package parts with a specified X.509 certificate.

SignDigitally(X509Certificate, Boolean, XpsDigSigPartAlteringRestrictions, Guid)

Assina uma coleção de partes do pacote usando um certificado X.509 especificado.Signs a collection of package parts by using a specified X.509 certificate.

SignDigitally(X509Certificate, Boolean, XpsDigSigPartAlteringRestrictions, Guid, Boolean)

Assina uma coleção de partes do pacote com um certificado X.509 especificado.Signs a collection of package parts with a specified X.509 certificate.

Exemplos

O exemplo a seguir mostra como usar o método SignDigitally.The following example shows how to use the SignDigitally method.


// ------------------------------ SignXps -----------------------------
/// <summary>
///   Signs an XPS document with a given X509 certificate, and if one
///   exists, associates the signature with a given SignatureDefintion
///   spotId GUID.</summary>
/// <param name="xpsDocument">
///   The XPS document to sign.</param>
/// <param name="cert">
///   The X509 certificate to use for signing.</param>
/// <param name="spotId">
///   The nullable spotId GUID of the signature definition.</param>
public void SignXps(
    XpsDocument xpsDocument, X509Certificate cert, Guid? spotId )
{
    // If there's a SignatureDefinition spotId,
    // associate it with the signature.
    if (spotId != null)
    {
        xpsDocument.SignDigitally(
            cert, true, XpsDigSigPartAlteringRestrictions.None,
            spotId.Value);
    }
    else
    {
        xpsDocument.SignDigitally(
            cert, true, XpsDigSigPartAlteringRestrictions.None);
    }

}// end:SignXps()


' ------------------------------ SignXps -----------------------------
''' <summary>
'''   Signs an XPS document with a given X509 certificate, and if one
'''   exists, associates the signature with a given SignatureDefintion
'''   spotId GUID.</summary>
''' <param name="xpsDocument">
'''   The XPS document to sign.</param>
''' <param name="cert">
'''   The X509 certificate to use for signing.</param>
''' <param name="spotId">
'''   The nullable spotId GUID of the signature definition.</param>
Public Sub SignXps(xpsDocument As XpsDocument, cert As X509Certificate, spotId? As Guid)
    ' If there's a SignatureDefinition spotId,
    ' associate it with the signature.
    If spotId IsNot Nothing Then
        xpsDocument.SignDigitally(cert, True, XpsDigSigPartAlteringRestrictions.None, spotId.Value)
    Else
        xpsDocument.SignDigitally(cert, True, XpsDigSigPartAlteringRestrictions.None)
    End If

End Sub

SignDigitally(X509Certificate, Boolean, XpsDigSigPartAlteringRestrictions)

Assina uma coleção de partes do pacote com um certificado X.509 especificado.Signs a collection of package parts with a specified X.509 certificate.

public:
 System::Windows::Xps::Packaging::XpsDigitalSignature ^ SignDigitally(System::Security::Cryptography::X509Certificates::X509Certificate ^ certificate, bool embedCertificate, System::Windows::Xps::Packaging::XpsDigSigPartAlteringRestrictions restrictions);
public System.Windows.Xps.Packaging.XpsDigitalSignature SignDigitally (System.Security.Cryptography.X509Certificates.X509Certificate certificate, bool embedCertificate, System.Windows.Xps.Packaging.XpsDigSigPartAlteringRestrictions restrictions);
member this.SignDigitally : System.Security.Cryptography.X509Certificates.X509Certificate * bool * System.Windows.Xps.Packaging.XpsDigSigPartAlteringRestrictions -> System.Windows.Xps.Packaging.XpsDigitalSignature
Public Function SignDigitally (certificate As X509Certificate, embedCertificate As Boolean, restrictions As XpsDigSigPartAlteringRestrictions) As XpsDigitalSignature

Parâmetros

certificate
X509Certificate

O certificado X.509 a ser usado na assinatura de cada parte; ou null para solicitar que o usuário selecione um certificado instalado.The X.509 certificate to use in signing each part; or null to prompt the user to select an installed certificate.

embedCertificate
Boolean

true para armazenar o certificado no pacote; caso contrário, false.true to store the certificate in the package; otherwise, false.

restrictions
XpsDigSigPartAlteringRestrictions

Sinalizadores que indicam quais partes dependentes devem ser excluídas da assinatura.Flags that indicate what dependent parts must be excluded from the signing.

Retornos

Um XpsDigitalSignature que contém informações sobre a assinatura.An XpsDigitalSignature that contains information about the signature.

Exemplos

O exemplo a seguir mostra como usar o método SignDigitally.The following example shows how to use the SignDigitally method.


// ------------------------------ SignXps -----------------------------
/// <summary>
///   Signs an XPS document with a given X509 certificate, and if one
///   exists, associates the signature with a given SignatureDefintion
///   spotId GUID.</summary>
/// <param name="xpsDocument">
///   The XPS document to sign.</param>
/// <param name="cert">
///   The X509 certificate to use for signing.</param>
/// <param name="spotId">
///   The nullable spotId GUID of the signature definition.</param>
public void SignXps(
    XpsDocument xpsDocument, X509Certificate cert, Guid? spotId )
{
    // If there's a SignatureDefinition spotId,
    // associate it with the signature.
    if (spotId != null)
    {
        xpsDocument.SignDigitally(
            cert, true, XpsDigSigPartAlteringRestrictions.None,
            spotId.Value);
    }
    else
    {
        xpsDocument.SignDigitally(
            cert, true, XpsDigSigPartAlteringRestrictions.None);
    }

}// end:SignXps()


' ------------------------------ SignXps -----------------------------
''' <summary>
'''   Signs an XPS document with a given X509 certificate, and if one
'''   exists, associates the signature with a given SignatureDefintion
'''   spotId GUID.</summary>
''' <param name="xpsDocument">
'''   The XPS document to sign.</param>
''' <param name="cert">
'''   The X509 certificate to use for signing.</param>
''' <param name="spotId">
'''   The nullable spotId GUID of the signature definition.</param>
Public Sub SignXps(xpsDocument As XpsDocument, cert As X509Certificate, spotId? As Guid)
    ' If there's a SignatureDefinition spotId,
    ' associate it with the signature.
    If spotId IsNot Nothing Then
        xpsDocument.SignDigitally(cert, True, XpsDigSigPartAlteringRestrictions.None, spotId.Value)
    Else
        xpsDocument.SignDigitally(cert, True, XpsDigSigPartAlteringRestrictions.None)
    End If

End Sub

Comentários

Se certificate for null, será exibida uma caixa de diálogo que permite ao usuário selecionar um certificado X. 509 instalado, como de um leitor de cartão inteligente.If certificate is null, a dialog box appears that enables the user to select an installed X.509 certificate, such as from a smart card reader.

SignDigitally(X509Certificate, Boolean, XpsDigSigPartAlteringRestrictions, Guid)

Assina uma coleção de partes do pacote usando um certificado X.509 especificado.Signs a collection of package parts by using a specified X.509 certificate.

public:
 System::Windows::Xps::Packaging::XpsDigitalSignature ^ SignDigitally(System::Security::Cryptography::X509Certificates::X509Certificate ^ certificate, bool embedCertificate, System::Windows::Xps::Packaging::XpsDigSigPartAlteringRestrictions restrictions, Guid id);
public System.Windows.Xps.Packaging.XpsDigitalSignature SignDigitally (System.Security.Cryptography.X509Certificates.X509Certificate certificate, bool embedCertificate, System.Windows.Xps.Packaging.XpsDigSigPartAlteringRestrictions restrictions, Guid id);
member this.SignDigitally : System.Security.Cryptography.X509Certificates.X509Certificate * bool * System.Windows.Xps.Packaging.XpsDigSigPartAlteringRestrictions * Guid -> System.Windows.Xps.Packaging.XpsDigitalSignature
Public Function SignDigitally (certificate As X509Certificate, embedCertificate As Boolean, restrictions As XpsDigSigPartAlteringRestrictions, id As Guid) As XpsDigitalSignature

Parâmetros

certificate
X509Certificate

O certificado X.509 a ser usado na assinatura de cada parte; ou null para solicitar que o usuário selecione um certificado instalado.The X.509 certificate to use in signing each part; or null to prompt the user to select an installed certificate.

embedCertificate
Boolean

true para armazenar o certificado no pacote; caso contrário, false.true to store the certificate in the package; otherwise, false.

restrictions
XpsDigSigPartAlteringRestrictions

Sinalizadores que indicam quais partes dependentes são excluídas da assinatura.Flags that indicate what dependent parts are excluded from the signing.

id
Guid

A ID a ser atribuída à assinatura.The ID to assign to the signature.

Retornos

Um XpsDigitalSignature que contém informações sobre a assinatura.An XpsDigitalSignature that contains information about the signature.

Exemplos

O exemplo a seguir mostra como usar o método SignDigitally.The following example shows how to use the SignDigitally method.


// ------------------------------ SignXps -----------------------------
/// <summary>
///   Signs an XPS document with a given X509 certificate, and if one
///   exists, associates the signature with a given SignatureDefintion
///   spotId GUID.</summary>
/// <param name="xpsDocument">
///   The XPS document to sign.</param>
/// <param name="cert">
///   The X509 certificate to use for signing.</param>
/// <param name="spotId">
///   The nullable spotId GUID of the signature definition.</param>
public void SignXps(
    XpsDocument xpsDocument, X509Certificate cert, Guid? spotId )
{
    // If there's a SignatureDefinition spotId,
    // associate it with the signature.
    if (spotId != null)
    {
        xpsDocument.SignDigitally(
            cert, true, XpsDigSigPartAlteringRestrictions.None,
            spotId.Value);
    }
    else
    {
        xpsDocument.SignDigitally(
            cert, true, XpsDigSigPartAlteringRestrictions.None);
    }

}// end:SignXps()


' ------------------------------ SignXps -----------------------------
''' <summary>
'''   Signs an XPS document with a given X509 certificate, and if one
'''   exists, associates the signature with a given SignatureDefintion
'''   spotId GUID.</summary>
''' <param name="xpsDocument">
'''   The XPS document to sign.</param>
''' <param name="cert">
'''   The X509 certificate to use for signing.</param>
''' <param name="spotId">
'''   The nullable spotId GUID of the signature definition.</param>
Public Sub SignXps(xpsDocument As XpsDocument, cert As X509Certificate, spotId? As Guid)
    ' If there's a SignatureDefinition spotId,
    ' associate it with the signature.
    If spotId IsNot Nothing Then
        xpsDocument.SignDigitally(cert, True, XpsDigSigPartAlteringRestrictions.None, spotId.Value)
    Else
        xpsDocument.SignDigitally(cert, True, XpsDigSigPartAlteringRestrictions.None)
    End If

End Sub

Comentários

Se certificate for null, será exibida uma caixa de diálogo que permite ao usuário selecionar um certificado X. 509 instalado, como de um leitor de cartão inteligente.If certificate is null, a dialog box appears that enables the user to select an installed X.509 certificate, such as from a smart card reader.

SignDigitally(X509Certificate, Boolean, XpsDigSigPartAlteringRestrictions, Guid, Boolean)

Assina uma coleção de partes do pacote com um certificado X.509 especificado.Signs a collection of package parts with a specified X.509 certificate.

public:
 System::Windows::Xps::Packaging::XpsDigitalSignature ^ SignDigitally(System::Security::Cryptography::X509Certificates::X509Certificate ^ certificate, bool embedCertificate, System::Windows::Xps::Packaging::XpsDigSigPartAlteringRestrictions restrictions, Guid id, bool testIsSignable);
public System.Windows.Xps.Packaging.XpsDigitalSignature SignDigitally (System.Security.Cryptography.X509Certificates.X509Certificate certificate, bool embedCertificate, System.Windows.Xps.Packaging.XpsDigSigPartAlteringRestrictions restrictions, Guid id, bool testIsSignable);
member this.SignDigitally : System.Security.Cryptography.X509Certificates.X509Certificate * bool * System.Windows.Xps.Packaging.XpsDigSigPartAlteringRestrictions * Guid * bool -> System.Windows.Xps.Packaging.XpsDigitalSignature
Public Function SignDigitally (certificate As X509Certificate, embedCertificate As Boolean, restrictions As XpsDigSigPartAlteringRestrictions, id As Guid, testIsSignable As Boolean) As XpsDigitalSignature

Parâmetros

certificate
X509Certificate

O certificado X.509 a ser usado na assinatura de cada parte; ou null para solicitar que o usuário selecione um certificado instalado.The X.509 certificate to use in signing each part; or null to prompt the user to select an installed certificate.

embedCertificate
Boolean

true para armazenar o certificado no pacote; caso contrário, false.true to store the certificate in the package; otherwise, false.

restrictions
XpsDigSigPartAlteringRestrictions

Sinalizadores que indicam quais partes dependentes a serem excluídas da assinatura.Flags that indicate what dependent parts to exclude from the signing.

id
Guid

A ID a ser atribuída à assinatura.The ID to assign to the signature.

testIsSignable
Boolean

true para verificar se IsSignable é true antes de assinar; caso contrário, false.true to verify that IsSignable is true before signing; otherwise, false.

Retornos

Um XpsDigitalSignature que contém informações sobre a assinatura.An XpsDigitalSignature that contains information about the signature.

Exemplos

O exemplo a seguir mostra como usar o método SignDigitally.The following example shows how to use the SignDigitally method.


// ------------------------------ SignXps -----------------------------
/// <summary>
///   Signs an XPS document with a given X509 certificate, and if one
///   exists, associates the signature with a given SignatureDefintion
///   spotId GUID.</summary>
/// <param name="xpsDocument">
///   The XPS document to sign.</param>
/// <param name="cert">
///   The X509 certificate to use for signing.</param>
/// <param name="spotId">
///   The nullable spotId GUID of the signature definition.</param>
public void SignXps(
    XpsDocument xpsDocument, X509Certificate cert, Guid? spotId )
{
    // If there's a SignatureDefinition spotId,
    // associate it with the signature.
    if (spotId != null)
    {
        xpsDocument.SignDigitally(
            cert, true, XpsDigSigPartAlteringRestrictions.None,
            spotId.Value);
    }
    else
    {
        xpsDocument.SignDigitally(
            cert, true, XpsDigSigPartAlteringRestrictions.None);
    }

}// end:SignXps()


' ------------------------------ SignXps -----------------------------
''' <summary>
'''   Signs an XPS document with a given X509 certificate, and if one
'''   exists, associates the signature with a given SignatureDefintion
'''   spotId GUID.</summary>
''' <param name="xpsDocument">
'''   The XPS document to sign.</param>
''' <param name="cert">
'''   The X509 certificate to use for signing.</param>
''' <param name="spotId">
'''   The nullable spotId GUID of the signature definition.</param>
Public Sub SignXps(xpsDocument As XpsDocument, cert As X509Certificate, spotId? As Guid)
    ' If there's a SignatureDefinition spotId,
    ' associate it with the signature.
    If spotId IsNot Nothing Then
        xpsDocument.SignDigitally(cert, True, XpsDigSigPartAlteringRestrictions.None, spotId.Value)
    Else
        xpsDocument.SignDigitally(cert, True, XpsDigSigPartAlteringRestrictions.None)
    End If

End Sub

Comentários

Se certificate for null, será apresentada uma caixa de diálogo que permite ao usuário selecionar um certificado X. 509 instalado, como de um leitor de cartão inteligente.If certificate is null, a dialog box is presented that enables the user to select an installed X.509 certificate, such as from a smart card reader.

CryptographicException será gerada se certificate estiver null e nenhum certificado estiver instalado.CryptographicException is thrown if certificate is null and no certificates are installed.

Aplica-se a