PdfDigitalSignatureDetails
Inheritance: java.lang.Object
public class PdfDigitalSignatureDetails
Contains details for signing a PDF document with a digital signature.
Remarks:
At the moment digitally signing PDF documents is only available on .NET 3.5 or higher.
To digitally sign a PDF document when it is created by Aspose.Words, set the PdfSaveOptions.getDigitalSignatureDetails() / PdfSaveOptions.setDigitalSignatureDetails(com.aspose.words.PdfDigitalSignatureDetails) 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.
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(getMyDir() + "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.
Calendar calendar = Calendar.getInstance();
calendar.set(2015, Calendar.JULY, 20);
Date signingTime = calendar.getTime();
options.setDigitalSignatureDetails(new PdfDigitalSignatureDetails(certificateHolder, "Test Signing", "My Office", signingTime));
options.getDigitalSignatureDetails().setHashAlgorithm(PdfDigitalSignatureHashAlgorithm.RIPE_MD_160);
Assert.assertEquals(options.getDigitalSignatureDetails().getReason(), "Test Signing");
Assert.assertEquals(options.getDigitalSignatureDetails().getLocation(), "My Office");
Assert.assertEquals(DocumentHelper.getLocalDate(options.getDigitalSignatureDetails().getSignatureDate()), DocumentHelper.getLocalDate(signingTime));
doc.save(getArtifactsDir() + "PdfSaveOptions.PdfDigitalSignature.pdf", options);
Constructors
Constructor | Description |
---|---|
PdfDigitalSignatureDetails() | Initializes an instance of this class. |
PdfDigitalSignatureDetails(CertificateHolder certificateHolder, String reason, String location, Date signatureDate) | Initializes an instance of this class. |
Methods
Method | Description |
---|---|
getCertificateHolder() | Returns the certificate holder object that contains the certificate was used to sign the document. |
getHashAlgorithm() | Gets the hash algorithm. |
getLocation() | Gets the location of the signing. |
getReason() | Gets the reason for the signing. |
getSignatureDate() | Gets the date of the signing. |
getTimestampSettings() | Gets the digital signature timestamp settings. |
setCertificateHolder(CertificateHolder value) | Returns the certificate holder object that contains the certificate was used to sign the document. |
setHashAlgorithm(int value) | Sets the hash algorithm. |
setLocation(String value) | Sets the location of the signing. |
setReason(String value) | Sets the reason for the signing. |
setSignatureDate(Date value) | Sets the date of the signing. |
setTimestampSettings(PdfDigitalSignatureTimestampSettings value) | Sets the digital signature timestamp settings. |
PdfDigitalSignatureDetails()
public PdfDigitalSignatureDetails()
Initializes an instance of this class.
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(getMyDir() + "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.
Calendar calendar = Calendar.getInstance();
calendar.set(2015, Calendar.JULY, 20);
Date signingTime = calendar.getTime();
options.setDigitalSignatureDetails(new PdfDigitalSignatureDetails(certificateHolder, "Test Signing", "My Office", signingTime));
options.getDigitalSignatureDetails().setHashAlgorithm(PdfDigitalSignatureHashAlgorithm.RIPE_MD_160);
Assert.assertEquals(options.getDigitalSignatureDetails().getReason(), "Test Signing");
Assert.assertEquals(options.getDigitalSignatureDetails().getLocation(), "My Office");
Assert.assertEquals(DocumentHelper.getLocalDate(options.getDigitalSignatureDetails().getSignatureDate()), DocumentHelper.getLocalDate(signingTime));
doc.save(getArtifactsDir() + "PdfSaveOptions.PdfDigitalSignature.pdf", options);
PdfDigitalSignatureDetails(CertificateHolder certificateHolder, String reason, String location, Date signatureDate)
public PdfDigitalSignatureDetails(CertificateHolder certificateHolder, String reason, String location, Date signatureDate)
Initializes an instance of this class.
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(getMyDir() + "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.
Calendar calendar = Calendar.getInstance();
calendar.set(2015, Calendar.JULY, 20);
Date signingTime = calendar.getTime();
options.setDigitalSignatureDetails(new PdfDigitalSignatureDetails(certificateHolder, "Test Signing", "My Office", signingTime));
options.getDigitalSignatureDetails().setHashAlgorithm(PdfDigitalSignatureHashAlgorithm.RIPE_MD_160);
Assert.assertEquals(options.getDigitalSignatureDetails().getReason(), "Test Signing");
Assert.assertEquals(options.getDigitalSignatureDetails().getLocation(), "My Office");
Assert.assertEquals(DocumentHelper.getLocalDate(options.getDigitalSignatureDetails().getSignatureDate()), DocumentHelper.getLocalDate(signingTime));
doc.save(getArtifactsDir() + "PdfSaveOptions.PdfDigitalSignature.pdf", options);
Parameters:
Parameter | Type | Description |
---|---|---|
certificateHolder | CertificateHolder | A certificate holder which contains the certificate itself. |
reason | java.lang.String | The reason for signing. |
location | java.lang.String | The location of signing. |
signatureDate | java.util.Date | The date and time of signing. |
getCertificateHolder()
public CertificateHolder getCertificateHolder()
Returns the certificate holder object that contains the certificate was used to sign the document.
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(getMyDir() + "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.
Calendar calendar = Calendar.getInstance();
calendar.set(2015, Calendar.JULY, 20);
Date signingTime = calendar.getTime();
options.setDigitalSignatureDetails(new PdfDigitalSignatureDetails(certificateHolder, "Test Signing", "My Office", signingTime));
options.getDigitalSignatureDetails().setHashAlgorithm(PdfDigitalSignatureHashAlgorithm.RIPE_MD_160);
Assert.assertEquals(options.getDigitalSignatureDetails().getReason(), "Test Signing");
Assert.assertEquals(options.getDigitalSignatureDetails().getLocation(), "My Office");
Assert.assertEquals(DocumentHelper.getLocalDate(options.getDigitalSignatureDetails().getSignatureDate()), DocumentHelper.getLocalDate(signingTime));
doc.save(getArtifactsDir() + "PdfSaveOptions.PdfDigitalSignature.pdf", options);
Returns: CertificateHolder - The certificate holder object that contains the certificate was used to sign the document.
getHashAlgorithm()
public int getHashAlgorithm()
Gets the hash algorithm.
Remarks:
The default value is the SHA-256 algorithm.
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(getMyDir() + "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.
Calendar calendar = Calendar.getInstance();
calendar.set(2015, Calendar.JULY, 20);
Date signingTime = calendar.getTime();
options.setDigitalSignatureDetails(new PdfDigitalSignatureDetails(certificateHolder, "Test Signing", "My Office", signingTime));
options.getDigitalSignatureDetails().setHashAlgorithm(PdfDigitalSignatureHashAlgorithm.RIPE_MD_160);
Assert.assertEquals(options.getDigitalSignatureDetails().getReason(), "Test Signing");
Assert.assertEquals(options.getDigitalSignatureDetails().getLocation(), "My Office");
Assert.assertEquals(DocumentHelper.getLocalDate(options.getDigitalSignatureDetails().getSignatureDate()), DocumentHelper.getLocalDate(signingTime));
doc.save(getArtifactsDir() + "PdfSaveOptions.PdfDigitalSignature.pdf", options);
Returns: int - The hash algorithm. The returned value is one of PdfDigitalSignatureHashAlgorithm constants.
getLocation()
public String getLocation()
Gets the location of the signing.
Remarks:
The default value is null .
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(getMyDir() + "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.
Calendar calendar = Calendar.getInstance();
calendar.set(2015, Calendar.JULY, 20);
Date signingTime = calendar.getTime();
options.setDigitalSignatureDetails(new PdfDigitalSignatureDetails(certificateHolder, "Test Signing", "My Office", signingTime));
options.getDigitalSignatureDetails().setHashAlgorithm(PdfDigitalSignatureHashAlgorithm.RIPE_MD_160);
Assert.assertEquals(options.getDigitalSignatureDetails().getReason(), "Test Signing");
Assert.assertEquals(options.getDigitalSignatureDetails().getLocation(), "My Office");
Assert.assertEquals(DocumentHelper.getLocalDate(options.getDigitalSignatureDetails().getSignatureDate()), DocumentHelper.getLocalDate(signingTime));
doc.save(getArtifactsDir() + "PdfSaveOptions.PdfDigitalSignature.pdf", options);
Returns: java.lang.String - The location of the signing.
getReason()
public String getReason()
Gets the reason for the signing.
Remarks:
The default value is null .
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(getMyDir() + "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.
Calendar calendar = Calendar.getInstance();
calendar.set(2015, Calendar.JULY, 20);
Date signingTime = calendar.getTime();
options.setDigitalSignatureDetails(new PdfDigitalSignatureDetails(certificateHolder, "Test Signing", "My Office", signingTime));
options.getDigitalSignatureDetails().setHashAlgorithm(PdfDigitalSignatureHashAlgorithm.RIPE_MD_160);
Assert.assertEquals(options.getDigitalSignatureDetails().getReason(), "Test Signing");
Assert.assertEquals(options.getDigitalSignatureDetails().getLocation(), "My Office");
Assert.assertEquals(DocumentHelper.getLocalDate(options.getDigitalSignatureDetails().getSignatureDate()), DocumentHelper.getLocalDate(signingTime));
doc.save(getArtifactsDir() + "PdfSaveOptions.PdfDigitalSignature.pdf", options);
Returns: java.lang.String - The reason for the signing.
getSignatureDate()
public Date getSignatureDate()
Gets the date of the signing.
Remarks:
The default value is the current time.
This value will appear in the digital signature as an unverified computer time.
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(getMyDir() + "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.
Calendar calendar = Calendar.getInstance();
calendar.set(2015, Calendar.JULY, 20);
Date signingTime = calendar.getTime();
options.setDigitalSignatureDetails(new PdfDigitalSignatureDetails(certificateHolder, "Test Signing", "My Office", signingTime));
options.getDigitalSignatureDetails().setHashAlgorithm(PdfDigitalSignatureHashAlgorithm.RIPE_MD_160);
Assert.assertEquals(options.getDigitalSignatureDetails().getReason(), "Test Signing");
Assert.assertEquals(options.getDigitalSignatureDetails().getLocation(), "My Office");
Assert.assertEquals(DocumentHelper.getLocalDate(options.getDigitalSignatureDetails().getSignatureDate()), DocumentHelper.getLocalDate(signingTime));
doc.save(getArtifactsDir() + "PdfSaveOptions.PdfDigitalSignature.pdf", options);
Returns: java.util.Date - The date of the signing.
getTimestampSettings()
public PdfDigitalSignatureTimestampSettings getTimestampSettings()
Gets the digital signature timestamp settings.
Remarks:
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.
Examples:
Shows how to sign a saved PDF document digitally and timestamp it.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.writeln("Signed PDF contents.");
// 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();
// Create a digital signature and assign it to our SaveOptions object to sign the document when we save it to PDF.
CertificateHolder certificateHolder = CertificateHolder.create(getMyDir() + "morzal.pfx", "aw");
options.setDigitalSignatureDetails(new PdfDigitalSignatureDetails(certificateHolder, "Test Signing", "Aspose Office", new Date()));
// Create a timestamp authority-verified timestamp.
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) 1800.0));
Assert.assertEquals(options.getDigitalSignatureDetails().getTimestampSettings().getTimeout(), 1800);
Assert.assertEquals(options.getDigitalSignatureDetails().getTimestampSettings().getServerUrl(), "https://freetsa.org/tsr");
Assert.assertEquals(options.getDigitalSignatureDetails().getTimestampSettings().getUserName(), "JohnDoe");
Assert.assertEquals(options.getDigitalSignatureDetails().getTimestampSettings().getPassword(), "MyPassword");
// The "Save" method will apply our signature to the output document at this time.
doc.save(getArtifactsDir() + "PdfSaveOptions.PdfDigitalSignatureTimestamp.pdf", options);
Returns: PdfDigitalSignatureTimestampSettings - The digital signature timestamp settings.
setCertificateHolder(CertificateHolder value)
public void setCertificateHolder(CertificateHolder value)
Returns the certificate holder object that contains the certificate was used to sign the document.
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(getMyDir() + "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.
Calendar calendar = Calendar.getInstance();
calendar.set(2015, Calendar.JULY, 20);
Date signingTime = calendar.getTime();
options.setDigitalSignatureDetails(new PdfDigitalSignatureDetails(certificateHolder, "Test Signing", "My Office", signingTime));
options.getDigitalSignatureDetails().setHashAlgorithm(PdfDigitalSignatureHashAlgorithm.RIPE_MD_160);
Assert.assertEquals(options.getDigitalSignatureDetails().getReason(), "Test Signing");
Assert.assertEquals(options.getDigitalSignatureDetails().getLocation(), "My Office");
Assert.assertEquals(DocumentHelper.getLocalDate(options.getDigitalSignatureDetails().getSignatureDate()), DocumentHelper.getLocalDate(signingTime));
doc.save(getArtifactsDir() + "PdfSaveOptions.PdfDigitalSignature.pdf", options);
Parameters:
Parameter | Type | Description |
---|---|---|
value | CertificateHolder | The certificate holder object that contains the certificate was used to sign the document. |
setHashAlgorithm(int value)
public void setHashAlgorithm(int value)
Sets the hash algorithm.
Remarks:
The default value is the SHA-256 algorithm.
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(getMyDir() + "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.
Calendar calendar = Calendar.getInstance();
calendar.set(2015, Calendar.JULY, 20);
Date signingTime = calendar.getTime();
options.setDigitalSignatureDetails(new PdfDigitalSignatureDetails(certificateHolder, "Test Signing", "My Office", signingTime));
options.getDigitalSignatureDetails().setHashAlgorithm(PdfDigitalSignatureHashAlgorithm.RIPE_MD_160);
Assert.assertEquals(options.getDigitalSignatureDetails().getReason(), "Test Signing");
Assert.assertEquals(options.getDigitalSignatureDetails().getLocation(), "My Office");
Assert.assertEquals(DocumentHelper.getLocalDate(options.getDigitalSignatureDetails().getSignatureDate()), DocumentHelper.getLocalDate(signingTime));
doc.save(getArtifactsDir() + "PdfSaveOptions.PdfDigitalSignature.pdf", options);
Parameters:
Parameter | Type | Description |
---|---|---|
value | int | The hash algorithm. The value must be one of PdfDigitalSignatureHashAlgorithm constants. |
setLocation(String value)
public void setLocation(String value)
Sets the location of the signing.
Remarks:
The default value is null .
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(getMyDir() + "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.
Calendar calendar = Calendar.getInstance();
calendar.set(2015, Calendar.JULY, 20);
Date signingTime = calendar.getTime();
options.setDigitalSignatureDetails(new PdfDigitalSignatureDetails(certificateHolder, "Test Signing", "My Office", signingTime));
options.getDigitalSignatureDetails().setHashAlgorithm(PdfDigitalSignatureHashAlgorithm.RIPE_MD_160);
Assert.assertEquals(options.getDigitalSignatureDetails().getReason(), "Test Signing");
Assert.assertEquals(options.getDigitalSignatureDetails().getLocation(), "My Office");
Assert.assertEquals(DocumentHelper.getLocalDate(options.getDigitalSignatureDetails().getSignatureDate()), DocumentHelper.getLocalDate(signingTime));
doc.save(getArtifactsDir() + "PdfSaveOptions.PdfDigitalSignature.pdf", options);
Parameters:
Parameter | Type | Description |
---|---|---|
value | java.lang.String | The location of the signing. |
setReason(String value)
public void setReason(String value)
Sets the reason for the signing.
Remarks:
The default value is null .
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(getMyDir() + "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.
Calendar calendar = Calendar.getInstance();
calendar.set(2015, Calendar.JULY, 20);
Date signingTime = calendar.getTime();
options.setDigitalSignatureDetails(new PdfDigitalSignatureDetails(certificateHolder, "Test Signing", "My Office", signingTime));
options.getDigitalSignatureDetails().setHashAlgorithm(PdfDigitalSignatureHashAlgorithm.RIPE_MD_160);
Assert.assertEquals(options.getDigitalSignatureDetails().getReason(), "Test Signing");
Assert.assertEquals(options.getDigitalSignatureDetails().getLocation(), "My Office");
Assert.assertEquals(DocumentHelper.getLocalDate(options.getDigitalSignatureDetails().getSignatureDate()), DocumentHelper.getLocalDate(signingTime));
doc.save(getArtifactsDir() + "PdfSaveOptions.PdfDigitalSignature.pdf", options);
Parameters:
Parameter | Type | Description |
---|---|---|
value | java.lang.String | The reason for the signing. |
setSignatureDate(Date value)
public void setSignatureDate(Date value)
Sets the date of the signing.
Remarks:
The default value is the current time.
This value will appear in the digital signature as an unverified computer time.
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(getMyDir() + "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.
Calendar calendar = Calendar.getInstance();
calendar.set(2015, Calendar.JULY, 20);
Date signingTime = calendar.getTime();
options.setDigitalSignatureDetails(new PdfDigitalSignatureDetails(certificateHolder, "Test Signing", "My Office", signingTime));
options.getDigitalSignatureDetails().setHashAlgorithm(PdfDigitalSignatureHashAlgorithm.RIPE_MD_160);
Assert.assertEquals(options.getDigitalSignatureDetails().getReason(), "Test Signing");
Assert.assertEquals(options.getDigitalSignatureDetails().getLocation(), "My Office");
Assert.assertEquals(DocumentHelper.getLocalDate(options.getDigitalSignatureDetails().getSignatureDate()), DocumentHelper.getLocalDate(signingTime));
doc.save(getArtifactsDir() + "PdfSaveOptions.PdfDigitalSignature.pdf", options);
Parameters:
Parameter | Type | Description |
---|---|---|
value | java.util.Date | The date of the signing. |
setTimestampSettings(PdfDigitalSignatureTimestampSettings value)
public void setTimestampSettings(PdfDigitalSignatureTimestampSettings value)
Sets the digital signature timestamp settings.
Remarks:
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.
Examples:
Shows how to sign a saved PDF document digitally and timestamp it.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.writeln("Signed PDF contents.");
// 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();
// Create a digital signature and assign it to our SaveOptions object to sign the document when we save it to PDF.
CertificateHolder certificateHolder = CertificateHolder.create(getMyDir() + "morzal.pfx", "aw");
options.setDigitalSignatureDetails(new PdfDigitalSignatureDetails(certificateHolder, "Test Signing", "Aspose Office", new Date()));
// Create a timestamp authority-verified timestamp.
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) 1800.0));
Assert.assertEquals(options.getDigitalSignatureDetails().getTimestampSettings().getTimeout(), 1800);
Assert.assertEquals(options.getDigitalSignatureDetails().getTimestampSettings().getServerUrl(), "https://freetsa.org/tsr");
Assert.assertEquals(options.getDigitalSignatureDetails().getTimestampSettings().getUserName(), "JohnDoe");
Assert.assertEquals(options.getDigitalSignatureDetails().getTimestampSettings().getPassword(), "MyPassword");
// The "Save" method will apply our signature to the output document at this time.
doc.save(getArtifactsDir() + "PdfSaveOptions.PdfDigitalSignatureTimestamp.pdf", options);
Parameters:
Parameter | Type | Description |
---|---|---|
value | PdfDigitalSignatureTimestampSettings | The digital signature timestamp settings. |