DigitalSignatureUtil class
DigitalSignatureUtil class
Provides methods for signing document. To learn more, visit the Work with Digital Signatures documentation article.
Remarks
Since digital signature works with file content rather than Document Object Model these methods are put into a separate class.
Supported formats are: LoadFormat.Doc, LoadFormat.Dot, LoadFormat.Docx, LoadFormat.Dotx, LoadFormat.Docm, LoadFormat.Dotm, LoadFormat.Odt, LoadFormat.Ott.
Methods
Examples
Shows how to load signatures from a digitally signed document.
// There are two ways of loading a signed document's collection of digital signatures using the DigitalSignatureUtil class.
// 1 - Load from a document from a local file system filename:
let digitalSignatures =
aw.DigitalSignatures.DigitalSignatureUtil.loadSignatures(base.myDir + "Digitally signed.docx");
// If this collection is nonempty, then we can verify that the document is digitally signed.
expect(digitalSignatures.count).toEqual(1);
// 2 - Load from a document from a Buffer:
let data = base.loadFileToBuffer(base.myDir + "Digitally signed.docx");
digitalSignatures = aw.DigitalSignatures.DigitalSignatureUtil.loadSignatures(data);
expect(digitalSignatures.count).toEqual(1);
Shows how to remove digital signatures from a digitally signed document.
// There are two ways of using the DigitalSignatureUtil class to remove digital signatures
// from a signed document by saving an unsigned copy of it somewhere else in the local file system.
// 1 - Determine the locations of both the signed document and the unsigned copy by filename strings:
aw.DigitalSignatures.DigitalSignatureUtil.removeAllSignatures(base.myDir + "Digitally signed.docx",
base.artifactsDir + "DigitalSignatureUtil.LoadAndRemove.FromString.docx");
// 2 - Determine the locations of both the signed document and the unsigned copy by file streams:
let streamIn = base.loadFileToBuffer(base.myDir + "Digitally signed.docx");
let streamOut = fs.createWriteStream(base.artifactsDir + "DigitalSignatureUtil.LoadAndRemove.FromStream.docx");
aw.DigitalSignatures.DigitalSignatureUtil.removeAllSignatures(streamIn, streamOut);
await new Promise(resolve => streamOut.on("finish", resolve));
// Verify that both our output documents have no digital signatures.
expect(aw.DigitalSignatures.DigitalSignatureUtil.loadSignatures(base.artifactsDir + "DigitalSignatureUtil.LoadAndRemove.FromString.docx").count).toEqual(0);
expect(aw.DigitalSignatures.DigitalSignatureUtil.loadSignatures(base.artifactsDir + "DigitalSignatureUtil.LoadAndRemove.FromStream.docx").count).toEqual(0);