PdfDigitalSignatureDetails

PdfDigitalSignatureDetails class

Contains details for signing a PDF document with a digital signature.

public class PdfDigitalSignatureDetails

Constructors

Name Description
PdfDigitalSignatureDetails() Initializes an instance of this class.
PdfDigitalSignatureDetails(CertificateHolder, string, string, DateTime) Initializes an instance of this class.

Properties

Name Description
CertificateHolder { get; set; } Returns the certificate holder object that contains the certificate was used to sign the document.
HashAlgorithm { get; set; } Gets or sets the hash algorithm.
Location { get; set; } Gets or sets the location of the signing.
Reason { get; set; } Gets or sets the reason for the signing.
SignatureDate { get; set; } Gets or sets the date of the signing.
TimestampSettings { get; set; } Gets or sets the digital signature timestamp settings.

Remarks

At the moment digitally signing PDF documents is only available on .NET 2.0 or higher.

To digitally sign a PDF document when it is created by Aspose.Words, set the DigitalSignatureDetails property to a valid PdfDigitalSignatureDetails object and then save the document in the PDF format passing the PdfSaveOptions as a parameter into the Save method.

Aspose.Words creates a PKCS#7 signature over the whole PDF document and uses the “Adobe.PPKMS” filter and “adbe.pkcs7.sha1” subfilter when creating a digital signature.

Examples

Shows how to sign a generated PDF document.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("Contents of signed PDF.");

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

// Create a "PdfSaveOptions" object that we can pass to the document's "Save" method
// to modify how that method converts the document to .PDF.
PdfSaveOptions options = new PdfSaveOptions();

// Configure the "DigitalSignatureDetails" object of the "SaveOptions" object to
// digitally sign the document as we render it with the "Save" method.
DateTime signingTime = DateTime.Now;
options.DigitalSignatureDetails =
    new PdfDigitalSignatureDetails(certificateHolder, "Test Signing", "My Office", signingTime);
options.DigitalSignatureDetails.HashAlgorithm = PdfDigitalSignatureHashAlgorithm.Sha256;

Assert.AreEqual("Test Signing", options.DigitalSignatureDetails.Reason);
Assert.AreEqual("My Office", options.DigitalSignatureDetails.Location);
Assert.AreEqual(signingTime.ToUniversalTime(), options.DigitalSignatureDetails.SignatureDate.ToUniversalTime());

doc.Save(ArtifactsDir + "PdfSaveOptions.PdfDigitalSignature.pdf", options);

See Also