Aspose.Words

Working with Digital Signatures

A digital signature is used to authenticate a document to establish that the sender of the document is who they say they are and the content of the document has not been tampered with.

Aspose.Words supports documents with digital signatures and provides access to them allowing you to detect and validate digital signatures on a document . At the present time digital signatures are supported on DOC, OOXML and ODT documents.

Digital Signatures are not Preserved on Open and Save

An important point to note is that a document loaded and then saved using Aspose.Words will lose any digital signatures signed on the document. This is by design as a digital signature ensures that the content has not been modified and furthermore authenticates the identify of who signed the document. These principles would be invalidated if the original signatures were carried over to the resulting document.

Due to this, if you process documents uploaded to a server this could potentially mean you may corrupt a document uploaded to your server in this way without knowing. Therefore it is best to check for digital signatures on a document and take the appropriate action if any are found, for example an alert can be sent to the client informing them that the document they are passing contains digital signatures which will be lost if it is processed.

Example DetectDocumentSignatures

Shows how to check a document for digital signatures before loading it into a Document object.

[Java]

 

// The path to the document which is to be processed.

String filePath = getMyDir() + "Document.Signed.docx";

 

FileFormatInfo info = FileFormatUtil.detectFileFormat(filePath);

if (info.hasDigitalSignature()) {

    System.out.println(java.text.MessageFormat.format(

            "Document {0} has digital signatures, they will be lost if you open/save this document with Aspose.Words.",

            new File(filePath).getName()));

}

 

 

The code above uses the FileFormatUtil.DetectFileFormat method to detect if a document contains digital signatures without loading the document first. This provides an efficient and safe way to check a document for signatures before processing them. When executed, the method returns a FileFormatInfo object which provides the property FileFormatInfo.HasDigitalSignature. This property returns true if the document contains one or more digital signatures. It’s important to note that this method does not validate the signatures, it only determines if signatures are present. Validating digital signatures is covered in the next section.

Digital Signatures on Macros (VBA Projects)

Digital signatures on macros cannot be accessed or signed. This is because Aspose.Words does not directly deal with macros in a document. However digital signatures on macros are preserved when exporting the document back to any word format. These signatures can be preserved on VBA code because the binary content of the macros are not changed even if the document itself is modified.