DigitalSignatureUtilSign Method (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.

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.3
Syntax
public static void Sign(
	Stream srcStream,
	Stream dstStream,
	CertificateHolder certHolder,
	SignOptions signOptions
)

Parameters

srcStream
Type: System.IOStream
The stream which contains the document to sign.
dstStream
Type: System.IOStream
The stream that signed document will be written to.
certHolder
Type: Aspose.WordsCertificateHolder
CertificateHolder object with certificate that used to sign file. The certificate in holder MUST contain private keys and have the X509KeyStorageFlags.Exportable flag set.
signOptions
Type: Aspose.WordsSignOptions
SignOptions object with various signing options.
Examples
Shows how to sign documents using certificate holder and sign options.
CertificateHolder certificateHolder = CertificateHolder.Create(MyDir + "morzal.pfx", "aw");

SignOptions signOptions = new SignOptions { Comments = "My comment", SignTime = DateTime.Now };

using (Stream streamIn = new FileStream(MyDir + "Digitally signed.docx", FileMode.Open))
{
    using (Stream streamOut = new FileStream(ArtifactsDir + "DigitalSignatureUtil.SignDocument.docx", FileMode.OpenOrCreate))
    {
        DigitalSignatureUtil.Sign(streamIn, streamOut, certificateHolder, signOptions);
    }
}
See Also