Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

XpsDocument.SignDigitally Method (X509Certificate, Boolean, XpsDigSigPartAlteringRestrictions, Guid, Boolean)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Signs a collection of package parts with a specified X.509 certificate.

Namespace:   System.Windows.Xps.Packaging
Assembly:  ReachFramework (in ReachFramework.dll)

public XpsDigitalSignature SignDigitally(
	X509Certificate certificate,
	bool embedCertificate,
	XpsDigSigPartAlteringRestrictions restrictions,
	Guid id,
	bool testIsSignable


Type: System.Security.Cryptography.X509Certificates.X509Certificate

The X.509 certificate to use in signing each part; or null to prompt the user to select an installed certificate.

Type: System.Boolean

true to store the certificate in the package; otherwise, false.

Type: System.Windows.Xps.Packaging.XpsDigSigPartAlteringRestrictions

Flags that indicate what dependent parts to exclude from the signing.

Type: System.Guid

The ID to assign to the signature.

Type: System.Boolean

true to verify that IsSignable is true before signing; otherwise, false.

Return Value

Type: System.Windows.Xps.Packaging.XpsDigitalSignature

An XpsDigitalSignature that contains information about the signature.

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 is thrown if certificate is null and no certificates are installed.

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)
            cert, true, XpsDigSigPartAlteringRestrictions.None,
            cert, true, XpsDigSigPartAlteringRestrictions.None);

}// end:SignXps()

.NET Framework
Available since 3.0
Return to top
© 2018 Microsoft