DigitalSignatureUtil Class

Provides methods for signing document.
Inheritance Hierarchy
SystemObject
  Aspose.WordsDigitalSignatureUtil

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.2
Syntax
public static class DigitalSignatureUtil
Methods
  NameDescription
Public methodStatic memberCode exampleLoadSignatures(Stream)
Loads digital signatures from document using stream.
Public methodStatic memberCode exampleLoadSignatures(String)
Loads digital signatures from document.
Public methodStatic memberCode exampleRemoveAllSignatures(Stream, Stream)
Removes all digital signatures from document in source stream and writes unsigned document to destination stream.

Output will be written to the start of stream and stream size will be updated with content length.

Public methodStatic memberCode exampleRemoveAllSignatures(String, String)
Removes all digital signatures from source file and writes unsigned file to destination file.
Public methodStatic memberCode exampleSign(Stream, Stream, CertificateHolder)
Signs source document using given CertificateHolder with digital signature and writes signed document to destination stream.

Document should be either Doc or Docx.

Output will be written to the start of stream and stream size will be updated with content length.

Public methodStatic memberCode exampleSign(String, String, CertificateHolder)
Signs source document using given CertificateHolder with digital signature and writes signed document to destination file.

Document should be either Doc or Docx.

Public methodStatic memberCode exampleSign(Stream, Stream, CertificateHolder, SignOptions)
Signs source document using given CertificateHolder and SignOptions with digital signature and writes signed document to destination stream.

Document should be either Doc or Docx.

Output will be written to the start of stream and stream size will be updated with content length.

Public methodStatic memberCode exampleSign(String, String, CertificateHolder, SignOptions)
Signs source document using given CertificateHolder and SignOptions with digital signature and writes signed document to destination file.

Document should be either Doc or Docx.

Remarks

Since digital signature works with file content rather than Document Object Model these methods are put into a separate class.

Supported formats are Doc and Docx.

Examples
Shows how to load and remove digital signatures from a digitally signed document.
// Load digital signatures via filename string to verify that the document is signed
DigitalSignatureCollection digitalSignatures = DigitalSignatureUtil.LoadSignatures(MyDir + "Digitally signed.docx");
Assert.AreEqual(1, digitalSignatures.Count);

// Re-save the document to an output filename with all digital signatures removed
DigitalSignatureUtil.RemoveAllSignatures(MyDir + "Digitally signed.docx", ArtifactsDir + "DigitalSignatureUtil.LoadAndRemove.FromString.docx");

// Remove all signatures from the document using stream parameters
using (Stream streamIn = new FileStream(MyDir + "Digitally signed.docx", FileMode.Open))
{
    using (Stream streamOut = new FileStream(ArtifactsDir + "DigitalSignatureUtil.LoadAndRemove.FromStream.docx", FileMode.Create))
    {
        DigitalSignatureUtil.RemoveAllSignatures(streamIn, streamOut);
    } 
}

// We can also load a document's digital signatures via stream, which we will do to verify that all signatures have been removed
using (Stream stream = new FileStream(ArtifactsDir + "DigitalSignatureUtil.LoadAndRemove.FromStream.docx", FileMode.Open))
{
    digitalSignatures = DigitalSignatureUtil.LoadSignatures(stream);
}

Assert.AreEqual(0, digitalSignatures.Count);
See Also