com.aspose.words

Class PdfDigitalSignatureDetails

  • java.lang.Object
    • com.aspose.words.PdfDigitalSignatureDetails
public class PdfDigitalSignatureDetails 
extends java.lang.Object

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

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 PdfSaveOptions.DigitalSignatureDetails property to a valid PdfDigitalSignatureDetails object and then save the document in the PDF format passing the PdfSaveOptions as a parameter into the Document.save(java.lang.String,com.aspose.words.SaveOptions) 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.

Example:

Shows how to sign a generated PDF using Aspose.Words.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.writeln("Signed PDF contents.");

// Load the certificate from disk
// The other constructor overloads can be used to load certificates from different locations
CertificateHolder certificateHolder = CertificateHolder.create(getMyDir() + "morzal.pfx", "aw");

// Pass the certificate and details to the save options class to sign with
PdfSaveOptions options = new PdfSaveOptions();
Date signingTime = new Date();
options.setDigitalSignatureDetails(new PdfDigitalSignatureDetails(certificateHolder, "Test Signing", "Aspose Office", signingTime));

// We can use this attribute to set a different hash algorithm
options.getDigitalSignatureDetails().setHashAlgorithm(PdfDigitalSignatureHashAlgorithm.SHA_256);

Assert.assertEquals(options.getDigitalSignatureDetails().getReason(), "Test Signing");
Assert.assertEquals(options.getDigitalSignatureDetails().getLocation(), "Aspose Office");
Assert.assertEquals(options.getDigitalSignatureDetails().getSignatureDate(), signingTime);

doc.save(getArtifactsDir() + "PdfSaveOptions.PdfDigitalSignature.pdf", options);
See Also:
PdfSaveOptions.DigitalSignatureDetails

Constructor Summary
PdfDigitalSignatureDetails()
Initializes an instance of this class.
PdfDigitalSignatureDetails(CertificateHolder certificateHolder, java.lang.Stringreason, java.lang.Stringlocation, java.util.DatesignatureDate)
Initializes an instance of this class.
 
Property Getters/Setters Summary
CertificateHoldergetCertificateHolder()
void
           Returns the certificate holder object that contains the certificate was used to sign the document.
intgetHashAlgorithm()
void
           Gets or sets the hash algorithm. The value of the property is PdfDigitalSignatureHashAlgorithm integer constant.
java.lang.StringgetLocation()
void
setLocation(java.lang.Stringvalue)
           Gets or sets the location of the signing.
java.lang.StringgetReason()
void
setReason(java.lang.Stringvalue)
           Gets or sets the reason for the signing.
java.util.DategetSignatureDate()
void
setSignatureDate(java.util.Datevalue)
           Gets or sets the date of the signing.
PdfDigitalSignatureTimestampSettingsgetTimestampSettings()
void
           Gets or sets the digital signature timestamp settings.
 

    • Constructor Detail

      • PdfDigitalSignatureDetails

        public PdfDigitalSignatureDetails()
        Initializes an instance of this class.

        Example:

        Shows how to sign a generated PDF using Aspose.Words.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        builder.writeln("Signed PDF contents.");
        
        // Load the certificate from disk
        // The other constructor overloads can be used to load certificates from different locations
        CertificateHolder certificateHolder = CertificateHolder.create(getMyDir() + "morzal.pfx", "aw");
        
        // Pass the certificate and details to the save options class to sign with
        PdfSaveOptions options = new PdfSaveOptions();
        Date signingTime = new Date();
        options.setDigitalSignatureDetails(new PdfDigitalSignatureDetails(certificateHolder, "Test Signing", "Aspose Office", signingTime));
        
        // We can use this attribute to set a different hash algorithm
        options.getDigitalSignatureDetails().setHashAlgorithm(PdfDigitalSignatureHashAlgorithm.SHA_256);
        
        Assert.assertEquals(options.getDigitalSignatureDetails().getReason(), "Test Signing");
        Assert.assertEquals(options.getDigitalSignatureDetails().getLocation(), "Aspose Office");
        Assert.assertEquals(options.getDigitalSignatureDetails().getSignatureDate(), signingTime);
        
        doc.save(getArtifactsDir() + "PdfSaveOptions.PdfDigitalSignature.pdf", options);
      • PdfDigitalSignatureDetails

        public PdfDigitalSignatureDetails(CertificateHolder certificateHolder, java.lang.String reason, java.lang.String location, java.util.Date signatureDate)
        Initializes an instance of this class.
        Parameters:
        certificateHolder - A certificate holder which contains the certificate itself.
        reason - The reason for signing.
        location - The location of signing.
        signatureDate - The date and time of signing.

        Example:

        Shows how to sign a generated PDF using Aspose.Words.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        builder.writeln("Signed PDF contents.");
        
        // Load the certificate from disk
        // The other constructor overloads can be used to load certificates from different locations
        CertificateHolder certificateHolder = CertificateHolder.create(getMyDir() + "morzal.pfx", "aw");
        
        // Pass the certificate and details to the save options class to sign with
        PdfSaveOptions options = new PdfSaveOptions();
        Date signingTime = new Date();
        options.setDigitalSignatureDetails(new PdfDigitalSignatureDetails(certificateHolder, "Test Signing", "Aspose Office", signingTime));
        
        // We can use this attribute to set a different hash algorithm
        options.getDigitalSignatureDetails().setHashAlgorithm(PdfDigitalSignatureHashAlgorithm.SHA_256);
        
        Assert.assertEquals(options.getDigitalSignatureDetails().getReason(), "Test Signing");
        Assert.assertEquals(options.getDigitalSignatureDetails().getLocation(), "Aspose Office");
        Assert.assertEquals(options.getDigitalSignatureDetails().getSignatureDate(), signingTime);
        
        doc.save(getArtifactsDir() + "PdfSaveOptions.PdfDigitalSignature.pdf", options);
    • Property Getters/Setters Detail

      • getCertificateHolder/setCertificateHolder

        public CertificateHolder getCertificateHolder() / public void setCertificateHolder(CertificateHolder value)
        
        Returns the certificate holder object that contains the certificate was used to sign the document.
      • getHashAlgorithm/setHashAlgorithm

        public int getHashAlgorithm() / public void setHashAlgorithm(int value)
        
        Gets or sets the hash algorithm. The value of the property is PdfDigitalSignatureHashAlgorithm integer constant.The default value is the SHA-512 algorithm.

        Example:

        Shows how to sign a generated PDF using Aspose.Words.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        builder.writeln("Signed PDF contents.");
        
        // Load the certificate from disk
        // The other constructor overloads can be used to load certificates from different locations
        CertificateHolder certificateHolder = CertificateHolder.create(getMyDir() + "morzal.pfx", "aw");
        
        // Pass the certificate and details to the save options class to sign with
        PdfSaveOptions options = new PdfSaveOptions();
        Date signingTime = new Date();
        options.setDigitalSignatureDetails(new PdfDigitalSignatureDetails(certificateHolder, "Test Signing", "Aspose Office", signingTime));
        
        // We can use this attribute to set a different hash algorithm
        options.getDigitalSignatureDetails().setHashAlgorithm(PdfDigitalSignatureHashAlgorithm.SHA_256);
        
        Assert.assertEquals(options.getDigitalSignatureDetails().getReason(), "Test Signing");
        Assert.assertEquals(options.getDigitalSignatureDetails().getLocation(), "Aspose Office");
        Assert.assertEquals(options.getDigitalSignatureDetails().getSignatureDate(), signingTime);
        
        doc.save(getArtifactsDir() + "PdfSaveOptions.PdfDigitalSignature.pdf", options);
      • getLocation/setLocation

        public java.lang.String getLocation() / public void setLocation(java.lang.String value)
        
        Gets or sets the location of the signing. The default value is null.

        Example:

        Shows how to sign a generated PDF using Aspose.Words.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        builder.writeln("Signed PDF contents.");
        
        // Load the certificate from disk
        // The other constructor overloads can be used to load certificates from different locations
        CertificateHolder certificateHolder = CertificateHolder.create(getMyDir() + "morzal.pfx", "aw");
        
        // Pass the certificate and details to the save options class to sign with
        PdfSaveOptions options = new PdfSaveOptions();
        Date signingTime = new Date();
        options.setDigitalSignatureDetails(new PdfDigitalSignatureDetails(certificateHolder, "Test Signing", "Aspose Office", signingTime));
        
        // We can use this attribute to set a different hash algorithm
        options.getDigitalSignatureDetails().setHashAlgorithm(PdfDigitalSignatureHashAlgorithm.SHA_256);
        
        Assert.assertEquals(options.getDigitalSignatureDetails().getReason(), "Test Signing");
        Assert.assertEquals(options.getDigitalSignatureDetails().getLocation(), "Aspose Office");
        Assert.assertEquals(options.getDigitalSignatureDetails().getSignatureDate(), signingTime);
        
        doc.save(getArtifactsDir() + "PdfSaveOptions.PdfDigitalSignature.pdf", options);
      • getReason/setReason

        public java.lang.String getReason() / public void setReason(java.lang.String value)
        
        Gets or sets the reason for the signing. The default value is null.

        Example:

        Shows how to sign a generated PDF using Aspose.Words.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        builder.writeln("Signed PDF contents.");
        
        // Load the certificate from disk
        // The other constructor overloads can be used to load certificates from different locations
        CertificateHolder certificateHolder = CertificateHolder.create(getMyDir() + "morzal.pfx", "aw");
        
        // Pass the certificate and details to the save options class to sign with
        PdfSaveOptions options = new PdfSaveOptions();
        Date signingTime = new Date();
        options.setDigitalSignatureDetails(new PdfDigitalSignatureDetails(certificateHolder, "Test Signing", "Aspose Office", signingTime));
        
        // We can use this attribute to set a different hash algorithm
        options.getDigitalSignatureDetails().setHashAlgorithm(PdfDigitalSignatureHashAlgorithm.SHA_256);
        
        Assert.assertEquals(options.getDigitalSignatureDetails().getReason(), "Test Signing");
        Assert.assertEquals(options.getDigitalSignatureDetails().getLocation(), "Aspose Office");
        Assert.assertEquals(options.getDigitalSignatureDetails().getSignatureDate(), signingTime);
        
        doc.save(getArtifactsDir() + "PdfSaveOptions.PdfDigitalSignature.pdf", options);
      • getSignatureDate/setSignatureDate

        public java.util.Date getSignatureDate() / public void setSignatureDate(java.util.Date value)
        
        Gets or sets the date of the signing.

        The default value is the current time.

        This value will appear in the digital signature as an unverified computer time.

        Example:

        Shows how to sign a generated PDF using Aspose.Words.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        builder.writeln("Signed PDF contents.");
        
        // Load the certificate from disk
        // The other constructor overloads can be used to load certificates from different locations
        CertificateHolder certificateHolder = CertificateHolder.create(getMyDir() + "morzal.pfx", "aw");
        
        // Pass the certificate and details to the save options class to sign with
        PdfSaveOptions options = new PdfSaveOptions();
        Date signingTime = new Date();
        options.setDigitalSignatureDetails(new PdfDigitalSignatureDetails(certificateHolder, "Test Signing", "Aspose Office", signingTime));
        
        // We can use this attribute to set a different hash algorithm
        options.getDigitalSignatureDetails().setHashAlgorithm(PdfDigitalSignatureHashAlgorithm.SHA_256);
        
        Assert.assertEquals(options.getDigitalSignatureDetails().getReason(), "Test Signing");
        Assert.assertEquals(options.getDigitalSignatureDetails().getLocation(), "Aspose Office");
        Assert.assertEquals(options.getDigitalSignatureDetails().getSignatureDate(), signingTime);
        
        doc.save(getArtifactsDir() + "PdfSaveOptions.PdfDigitalSignature.pdf", options);
      • getTimestampSettings/setTimestampSettings

        public PdfDigitalSignatureTimestampSettings getTimestampSettings() / public void setTimestampSettings(PdfDigitalSignatureTimestampSettings value)
        
        Gets or sets the digital signature timestamp settings.

        The default value is null and the digital signature will not be time-stamped. When this property is set to a valid PdfDigitalSignatureTimestampSettings object, then the digital signature in the PDF document will be time-stamped.

        Example:

        Shows how to sign a generated PDF and timestamp it using Aspose.Words.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        builder.writeln("Signed PDF contents.");
        
        // Create a digital signature for the document that we will save
        CertificateHolder certificateHolder = CertificateHolder.create(getMyDir() + "morzal.pfx", "aw");
        PdfSaveOptions options = new PdfSaveOptions();
        options.setDigitalSignatureDetails(new PdfDigitalSignatureDetails(certificateHolder, "Test Signing", "Aspose Office", new Date()));
        
        // We can set a verified timestamp for our signature as well, with a valid timestamp authority
        options.getDigitalSignatureDetails().setTimestampSettings(new PdfDigitalSignatureTimestampSettings("https://freetsa.org/tsr", "JohnDoe", "MyPassword"));
        
        // The default lifespan of the timestamp is 100 seconds
        Assert.assertEquals(options.getDigitalSignatureDetails().getTimestampSettings().getTimeout(), 100000);
        
        // We can set our own timeout period via the constructor
        options.getDigitalSignatureDetails().setTimestampSettings(new PdfDigitalSignatureTimestampSettings("https://freetsa.org/tsr", "JohnDoe", "MyPassword", (long) 30.0));
        
        Assert.assertEquals(options.getDigitalSignatureDetails().getTimestampSettings().getTimeout(), 30);
        Assert.assertEquals(options.getDigitalSignatureDetails().getTimestampSettings().getServerUrl(), "https://freetsa.org/tsr");
        Assert.assertEquals(options.getDigitalSignatureDetails().getTimestampSettings().getUserName(), "JohnDoe");
        Assert.assertEquals(options.getDigitalSignatureDetails().getTimestampSettings().getPassword(), "MyPassword");
        
        doc.save(getArtifactsDir() + "PdfSaveOptions.PdfDigitalSignatureTimestamp.pdf", options);