java.lang.Object
com.aspose.words.PdfDigitalSignatureDetails
public class PdfDigitalSignatureDetails
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 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:
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);
| Constructor Summary |
|---|
PdfDigitalSignatureDetails()
Initializes an instance of this class. |
PdfDigitalSignatureDetails(CertificateHolder certificateHolder, java.lang.String reason, java.lang.String location, java.util.Date signatureDate)
Initializes an instance of this class. |
| Property Getters/Setters Summary | ||
|---|---|---|
CertificateHolder | getCertificateHolder() | |
void | setCertificateHolder(CertificateHolder value) | |
| Returns the certificate holder object that contains the certificate was used to sign the document. | ||
int | getHashAlgorithm() | |
void | setHashAlgorithm(int value) | |
| Gets or sets the hash algorithm. The value of the property is PdfDigitalSignatureHashAlgorithm integer constant. | ||
java.lang.String | getLocation() | |
void | setLocation(java.lang.String value) | |
| Gets or sets the location of the signing. | ||
java.lang.String | getReason() | |
void | setReason(java.lang.String value) | |
| Gets or sets the reason for the signing. | ||
java.util.Date | getSignatureDate() | |
void | setSignatureDate(java.util.Date value) | |
| Gets or sets the date of the signing. | ||
PdfDigitalSignatureTimestampSettings | getTimestampSettings() | |
void | setTimestampSettings(PdfDigitalSignatureTimestampSettings value) | |
| Gets or sets the digital signature timestamp settings. | ||
| Constructor Detail |
|---|
public PdfDigitalSignatureDetails()
Example:
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);public PdfDigitalSignatureDetails(CertificateHolder certificateHolder, java.lang.String reason, java.lang.String location, java.util.Date signatureDate)
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 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);| Property Getters/Setters Detail |
|---|
getCertificateHolder/setCertificateHolder | |
public CertificateHolder getCertificateHolder() / public void setCertificateHolder(CertificateHolder value) | |
Example:
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);getHashAlgorithm/setHashAlgorithm | |
public int getHashAlgorithm() / public void setHashAlgorithm(int value) | |
Example:
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);getLocation/setLocation | |
public java.lang.String getLocation() / public void setLocation(java.lang.String value) | |
null.
Example:
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);getReason/setReason | |
public java.lang.String getReason() / public void setReason(java.lang.String value) | |
null.
Example:
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);getSignatureDate/setSignatureDate | |
public java.util.Date getSignatureDate() / public void setSignatureDate(java.util.Date value) | |
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 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);getTimestampSettings/setTimestampSettings | |
public PdfDigitalSignatureTimestampSettings getTimestampSettings() / public void setTimestampSettings(PdfDigitalSignatureTimestampSettings value) | |
The default value is null and the digital signature will not be time-stamped.
When this property is set to a valid
Example:
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);