XpsDocument.SignDigitally Método
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Assina uma coleção de partes do pacote usando um certificado X.509 especificado.
Sobrecargas
SignDigitally(X509Certificate, Boolean, XpsDigSigPartAlteringRestrictions) |
Assina uma coleção de partes do pacote com um certificado X.509 especificado. |
SignDigitally(X509Certificate, Boolean, XpsDigSigPartAlteringRestrictions, Guid) |
Assina uma coleção de partes do pacote usando um certificado X.509 especificado. |
SignDigitally(X509Certificate, Boolean, XpsDigSigPartAlteringRestrictions, Guid, Boolean) |
Assina uma coleção de partes do pacote com um certificado X.509 especificado. |
Exemplos
O exemplo a seguir mostra como usar o método SignDigitally.
// ------------------------------ 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.
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.
- embedCertificate
- Boolean
true
para armazenar o certificado no pacote; caso contrário, false
.
- restrictions
- XpsDigSigPartAlteringRestrictions
Sinalizadores que indicam quais partes dependentes devem ser excluídas da assinatura.
Retornos
Um XpsDigitalSignature que contém informações sobre a assinatura.
Exemplos
O exemplo a seguir mostra como usar o método SignDigitally.
// ------------------------------ 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 que o usuário selecione um certificado X.509 instalado, como de um leitor de cartão inteligente.
Aplica-se a
SignDigitally(X509Certificate, Boolean, XpsDigSigPartAlteringRestrictions, Guid)
Assina uma coleção de partes do pacote usando um certificado X.509 especificado.
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.
- embedCertificate
- Boolean
true
para armazenar o certificado no pacote; caso contrário, false
.
- restrictions
- XpsDigSigPartAlteringRestrictions
Sinalizadores que indicam quais partes dependentes são excluídas da assinatura.
- id
- Guid
A ID a ser atribuída à assinatura.
Retornos
Um XpsDigitalSignature que contém informações sobre a assinatura.
Exemplos
O exemplo a seguir mostra como usar o método SignDigitally.
// ------------------------------ 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 que o usuário selecione um certificado X.509 instalado, como de um leitor de cartão inteligente.
Aplica-se a
SignDigitally(X509Certificate, Boolean, XpsDigSigPartAlteringRestrictions, Guid, Boolean)
Assina uma coleção de partes do pacote com um certificado X.509 especificado.
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.
- embedCertificate
- Boolean
true
para armazenar o certificado no pacote; caso contrário, false
.
- restrictions
- XpsDigSigPartAlteringRestrictions
Sinalizadores que indicam quais partes dependentes a serem excluídas da assinatura.
- id
- Guid
A ID a ser atribuída à assinatura.
- testIsSignable
- Boolean
true
para verificar se IsSignable é true
antes de assinar; caso contrário, false
.
Retornos
Um XpsDigitalSignature que contém informações sobre a assinatura.
Exemplos
O exemplo a seguir mostra como usar o método SignDigitally.
// ------------------------------ 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 que o usuário selecione um certificado X.509 instalado, como de um leitor de cartão inteligente.
CryptographicException será gerado se certificate
for null
e nenhum certificado estiver instalado.