XpsDocument.SignDigitally Metode
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Menandatangani kumpulan bagian paket dengan menggunakan sertifikat X.509 tertentu.
Overload
SignDigitally(X509Certificate, Boolean, XpsDigSigPartAlteringRestrictions) |
Menandatangani kumpulan bagian paket dengan sertifikat X.509 tertentu. |
SignDigitally(X509Certificate, Boolean, XpsDigSigPartAlteringRestrictions, Guid) |
Menandatangani kumpulan bagian paket dengan menggunakan sertifikat X.509 tertentu. |
SignDigitally(X509Certificate, Boolean, XpsDigSigPartAlteringRestrictions, Guid, Boolean) |
Menandatangani kumpulan bagian paket dengan sertifikat X.509 tertentu. |
Contoh
Contoh berikut menunjukkan cara menggunakan SignDigitally metode .
// ------------------------------ 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)
Menandatangani kumpulan bagian paket dengan sertifikat X.509 tertentu.
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
Parameter
- certificate
- X509Certificate
Sertifikat X.509 untuk digunakan dalam menandatangani setiap bagian; atau null
untuk meminta pengguna untuk memilih sertifikat yang diinstal.
- embedCertificate
- Boolean
true
untuk menyimpan sertifikat dalam paket; jika tidak, false
.
- restrictions
- XpsDigSigPartAlteringRestrictions
Bendera yang menunjukkan bagian dependen apa yang harus dikecualikan dari penandatanganan.
Mengembalikan
Yang XpsDigitalSignature berisi informasi tentang tanda tangan.
Contoh
Contoh berikut menunjukkan cara menggunakan SignDigitally metode .
// ------------------------------ 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
Keterangan
Jika certificate
adalah null
, kotak dialog muncul yang memungkinkan pengguna untuk memilih sertifikat X.509 yang diinstal, seperti dari pembaca kartu pintar.
Berlaku untuk
SignDigitally(X509Certificate, Boolean, XpsDigSigPartAlteringRestrictions, Guid)
Menandatangani kumpulan bagian paket dengan menggunakan sertifikat X.509 tertentu.
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
Parameter
- certificate
- X509Certificate
Sertifikat X.509 untuk digunakan dalam menandatangani setiap bagian; atau null
untuk meminta pengguna untuk memilih sertifikat yang diinstal.
- embedCertificate
- Boolean
true
untuk menyimpan sertifikat dalam paket; jika tidak, false
.
- restrictions
- XpsDigSigPartAlteringRestrictions
Bendera yang menunjukkan bagian dependen apa yang dikecualikan dari penandatanganan.
- id
- Guid
ID yang akan ditetapkan ke tanda tangan.
Mengembalikan
Yang XpsDigitalSignature berisi informasi tentang tanda tangan.
Contoh
Contoh berikut menunjukkan cara menggunakan SignDigitally metode .
// ------------------------------ 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
Keterangan
Jika certificate
adalah null
, kotak dialog muncul yang memungkinkan pengguna untuk memilih sertifikat X.509 yang diinstal, seperti dari pembaca kartu pintar.
Berlaku untuk
SignDigitally(X509Certificate, Boolean, XpsDigSigPartAlteringRestrictions, Guid, Boolean)
Menandatangani kumpulan bagian paket dengan sertifikat X.509 tertentu.
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
Parameter
- certificate
- X509Certificate
Sertifikat X.509 untuk digunakan dalam menandatangani setiap bagian; atau null
untuk meminta pengguna untuk memilih sertifikat yang diinstal.
- embedCertificate
- Boolean
true
untuk menyimpan sertifikat dalam paket; jika tidak, false
.
- restrictions
- XpsDigSigPartAlteringRestrictions
Bendera yang menunjukkan bagian dependen apa yang akan dikecualikan dari penandatanganan.
- id
- Guid
ID yang akan ditetapkan ke tanda tangan.
- testIsSignable
- Boolean
true
untuk memverifikasi bahwa IsSignable adalah true
sebelum menandatangani; jika tidak, false
.
Mengembalikan
Yang XpsDigitalSignature berisi informasi tentang tanda tangan.
Contoh
Contoh berikut menunjukkan cara menggunakan SignDigitally metode .
// ------------------------------ 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
Keterangan
Jika certificate
adalah null
, kotak dialog disajikan yang memungkinkan pengguna untuk memilih sertifikat X.509 yang diinstal, seperti dari pembaca kartu pintar.
CryptographicException dilemparkan jika certificate
adalah null
dan tidak ada sertifikat yang diinstal.