DocumentSigner.Sign(String, String, SignatureOptions, SignatureInfo) Method
Signs a file with the specified signature and signature options.
Namespace: DevExpress.Office.DigitalSignatures
Assembly: DevExpress.Docs.v24.1.dll
NuGet Package: DevExpress.Document.Processor
Declaration
public void Sign(
string inputFileName,
string outputFileName,
SignatureOptions options,
SignatureInfo signatureInfo
)
Parameters
Name | Type | Description |
---|---|---|
inputFileName | String | The path to a file to be signed. |
outputFileName | String | The path to a file into which to save the result. |
options | SignatureOptions | An object that contains signature options. |
signatureInfo | SignatureInfo | An object that contains the signature information. |
Remarks
Use the Sign method to sign documents and save the result. Office File API supports signatures the following document formats:
- Microsoft Word
- Open XML (DOCX, DOTX, DOTM, DOCM)
- 97-2003 (DOC, DOT)
- Microsoft Excel
- Open XML (XLSX, XLTX, XLSM)
- 97-2003 binary file (XLS, XLT)
- Microsoft PowerPoint
- PPTX, PPT
The SignatureOptions class object allows you to specify validation data (certificate, hash algorithm, timestamp, etc.). Pass the SignatureInfo object to define the signer information.
The options and signatureInfo parameters cannot be null.
The code sample below signs and saves a Word and Excel document:
using DevExpress.Office.DigitalSignatures;
using System;
using System.Diagnostics;
using System.Security.Cryptography.X509Certificates;
static void Main(string[] args)
{
//Sign a workbook:
SignDocument("Template.xlsx", "Workbook_signed.xlsx");
//Sign a document:
SignDocument("Template.docx", "Template_signed.docx");
}
static void SignDocument(string path, string output)
{
DocumentSigner documentSigner = new DocumentSigner();
documentSigner.Sign(path, output,
CreateSignatureOptions(), CreateSignatureInfo());
}
//Specify a signature certificate and digest method:
static SignatureOptions CreateSignatureOptions()
{
X509Certificate2 certificate = new X509Certificate2("Certificate/SignDemo.pfx", "dxdemo");
Uri tsaServer = new Uri("https://freetsa.org/tsr");
SignatureOptions options = new SignatureOptions();
options.Certificate = certificate;
if (tsaServer != null)
options.TsaClient = new TsaClient(tsaServer, HashAlgorithmType.SHA256);
//In this example, certificate validation is skipped
options.SignatureFlags &= ~SignatureFlags.ValidateCertificate;
options.CertificateKeyUsageFlags = X509KeyUsageFlags.None;
options.DigestMethod = HashAlgorithmType.SHA256;
X509ChainPolicy policy = new X509ChainPolicy();
policy.RevocationMode = X509RevocationMode.NoCheck;
policy.RevocationFlag = X509RevocationFlag.ExcludeRoot;
policy.VerificationFlags |= X509VerificationFlags.AllowUnknownCertificateAuthority |
X509VerificationFlags.IgnoreCertificateAuthorityRevocationUnknown;
options.CertificatePolicy = policy;
options.TimestampCertificatePolicy = policy;
return options;
}
//Specify signer information:
static SignatureInfo CreateSignatureInfo()
{
SignatureInfo signatureInfo = new SignatureInfo();
signatureInfo.CommitmentType = CommitmentType.ProofOfApproval;
signatureInfo.Time = DateTime.UtcNow;
signatureInfo.ClaimedRoles.Clear();
signatureInfo.ClaimedRoles.Add("Sales Representative");
signatureInfo.Comments = "Demo Digital Signature";
return signatureInfo;
}
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the Sign(String, String, SignatureOptions, SignatureInfo) method.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.