FileSignDll Quick Manual
The library FileSignDll can be used for adding digital signatures to your .XML, .DOCX, .XLSX, .PPTX, .XPS and .DWFx files.
To initialize the library use the code snippets below. To register the library you must enter as parameter a valid serial number.
Office 2007, 2010 digital signature
//digitally sign an Office 2007, 2010 document
OfficeSign officeSign = new OfficeSign("enter your serial number");
//you will need a digital certificate for this
DigitalCertificates certificate = new DigitalCertificates();
//load the certificate from a PFX file
officeSign.DigitalSignatureCertificate =
certificate.LoadCertificate(File.ReadAllBytes("c:\\cert.pfx"), "123456");
//apply the digital signature to the DOCX document
officeSign.SignOfficeDocument("c:\\TestDOCX.docx", "c:\\TestDOCX[signed].docx");
//apply the digital signature to the XLSX document
officeSign.SignOfficeDocument("c:\\TestXLSX.xlsx", "c:\\TestXLSX[signed].xlsx");
DWFx digital signature
//digitally sign an DWFx document
DWFXSign dwfxSign = new DWFXSign("enter your serial number");
//you will need a digital certificate for this
DigitalCertificates certificate = new DigitalCertificates();
//load the certificate from a PFX file
dwfxSign.DigitalSignatureCertificate =
certificate.LoadCertificate(File.ReadAllBytes("c:\\cert.pfx"), "123456");
//optionally, set a signing intent
dwfxSign.SigningIntent = "I approve this drawing";
//optionally, set a signing location
dwfxSign.SigningLocation = "Europe bureau";
//apply the digital signature to the DWFx document
dwfxSig.SignDWFXDocument("c:\\TestDWFX.dwfx", "c:\\TestDWFX[signed].dwfx");
XPS digital signature
//digitally sign an XPS document
XPSSign xpsSign = new XPSSign("enter your serial number");
//you will need a digital certificate for this
DigitalCertificates certificate = new DigitalCertificates();
//load the certificate from a PFX file
xpsSign.DigitalSignatureCertificate =
certificate.LoadCertificate(File.ReadAllBytes("c:\\cert.pfx"), "123456");
//optionally, set a signing intent
xpsSign.SigningIntent = "I am the author of this document";
//optionally, set a signing location
xpsSign.SigningLocation = "Asia branch";
//apply the digital signature to the XPS document
xpsSign.SignXPSDocument("c:\\TestXPS.xps", "c:\\TestXPS[signed].xps");
XML digital signature
//digitally sign an XML document
XMLSign xmlSign = new XMLSign("enter your serial number");
//you will need a digital certificate for this
DigitalCertificates certificate = new DigitalCertificates();
//load the certificate from a PFX file
xmlSign.DigitalSignatureCertificate =
certificate.LoadCertificate(File.ReadAllBytes("c:\\cert.pfx"), "123456");
//apply the digital signature to the XML document
xmlSign.SignXMLDocument("c:\\TestXML.xml", "c:\\TestXML[signed].xml");
PKCS#7 digital signature
//digitally sign a file in PKCS#7 format
PKCS7Sign pkcs7Sign = new PKCS7Sign("enter your serial number");
//you will need a digital certificate for this
DigitalCertificates certificate = new DigitalCertificates();
//load the certificate from a PFX file
pkcs7Sign.DigitalSignatureCertificate =
certificate.LoadCertificate(File.ReadAllBytes("c:\\cert.pfx"), "123456");
//set a signing reason for this signature
pkcs7Sign.SigningReason = "I approve this document";
//optionally, the file can be time stamped
pkcs7Sign.TimeStamping.ServerURL = new Uri("http://ca.signfiles.com/TSAServer.aspx");
//the file can be saved as .p7s or .p7m file
pkcs7Sign.SignFile("c:\\test.txt", "c:\\test.txt.p7s");
//verify the signature
Console.WriteLine("Number of signatures: "
+ pkcs7Sign.GetNumberOfSignatures("c:\\test.txt.p7s"));
PKCS7SignatureInformation si =
pkcs7Sign.VerifyDigitalSignature("c:\\test.txt.p7s", 1);
Console.WriteLine("Original document name: " + si.DocumentName);
Console.WriteLine("Signature is valid: " + si.CheckSignature(false));
Console.WriteLine("Signing Certificate: " + si.SigningCertificate.SubjectName.Name);
Console.WriteLine("Signing Reason: " + si.SigningReason);
Console.WriteLine("Signing Date: " + si.SigningDate.ToString());
Console.WriteLine("Is timestamped: " + si.IsTimeStamped);
if (si.IsTimeStamped == true)
Console.WriteLine("TSA Certificate: " + si.TSACertificate.SubjectName.Name);
