Export (0) Print
Expand All

XpsDocument.SignDigitally Method (X509Certificate, Boolean, XpsDigSigPartAlteringRestrictions)

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
)

Parameters

certificate
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.
embedCertificate
Type: System.Boolean
true to store the certificate in the package; otherwise, false.
restrictions
Type: System.Windows.Xps.Packaging.XpsDigSigPartAlteringRestrictions
Flags that indicate what dependent parts must be excluded from the signing.

Return Value

Type: System.Windows.Xps.Packaging.XpsDigitalSignature
An XpsDigitalSignature that contains information about the signature.

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.

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



.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2014 Microsoft