Signer.Sign

Signer Sign method. Signs source document using given CertificateHolder and SignOptions with digital signature and writes signed document to destination stream.

Sign(Stream, Stream, CertificateHolderSignOptions)

Signs source document using given CertificateHolder and SignOptions with digital signature and writes signed document to destination stream.

Supported formats are: Doc, Dot, Docx, Dotx, Docm, Odt, Ott, Xps.

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

public static void Sign(Stream srcStream, Stream dstStream, CertificateHolder certHolder, 
    SignOptions signOptions = null)
ParameterTypeDescription
srcStreamStreamThe stream which contains the document to sign.
dstStreamStreamThe stream that signed document will be written to.
certHolderCertificateHolderCertificateHolder object with certificate that used to sign file. The certificate in holder MUST contain private keys and have the X509KeyStorageFlags.Exportable flag set.
signOptionsSignOptionsSignOptions object with various signing options.

Examples

Demonstrates how to sign document using streams.

CertificateHolder certHolder = CertificateHolder.Create(MyDir + "morzal.pfx", "aw");

using (Stream input = File.OpenRead(MyDir + "Simple.docx"))
using (Stream output = File.Create(ArtifactsDir + "Signed.docx"))
{
    Signer.Sign(input, output, certHolder);
}

See Also


Sign(string, string, CertificateHolderSignOptions)

Signs source document using given CertificateHolder and SignOptions with digital signature and writes signed document to destination file.

Supported formats are: Doc, Dot, Docx, Dotx, Docm, Dotm, Odt, Ott, Xps.

public static void Sign(string srcFileName, string dstFileName, CertificateHolder certHolder, 
    SignOptions signOptions = null)
ParameterTypeDescription
srcFileNameStringThe file name of the document to sign.
dstFileNameStringThe file name of the signed document output.
certHolderCertificateHolderCertificateHolder object with certificate that used to sign file. The certificate in holder MUST contain private keys and have the X509KeyStorageFlags.Exportable flag set.
signOptionsSignOptionsSignOptions object with various signing options.

Examples

Demonstrates how to sign document.

CertificateHolder certHolder = CertificateHolder.Create(MyDir + "morzal.pfx", "aw");

SignOptions signOptions = new SignOptions();
signOptions.Comments = "Test Signing";
signOptions.SignTime = DateTime.Now;

Signer.Sign(MyDir + "Simple.docx", ArtifactsDir + "Signed.docx", certHolder, signOptions);

Demonstrates how to sign document using Fluent API.

CertificateHolder certHolder = CertificateHolder.Create(MyDir + "morzal.pfx", "aw");

SignerContext context = new SignerContext();
context.CertificateHolder = certHolder;
context.SignOptions = new SignOptions() { XmlDsigLevel = XmlDsigLevel.XAdEsEpes };

Signer.Create(context)
    .From(MyDir + "Simple.docx")
    .To(ArtifactsDir + "Signed.docx")
    .Execute();

See Also