jPDFSecure Source Code Samples

Following are a number of Java samples that use jPDFSecure and some of its features: – Apply a digital signature to a document. This program loads a document, then loads a digital ID from a PKCS#12 file, and then creates and signs a signature field on the first page of the document.

You can create a sample PKCS#12 file using Java’s keytool program. The command line to create a test file is as follows:

keytool -genkey -keystore test.pfx -storetype pkcs12 -storepass store_pwd -keypass key_pwd -alias key_alias – This program encrypts a document and restricts permissions to only allow printing. – This program lists the encryption and permissions settings of a PDF document. – This program clears the encryption and allows all permissions in a PDF document. – This sample applies applies a digital signature to a document with a custom appearance. The appearance of signatures can be modified in jPDFSecure to include an image, choose the fields that show or custom text. – This sample applies a digital signature using a hardware token through PKCS#11.  To use PKCS#11 in Java requires a configuration file that points to the native library that provides access to the hardware token.  This sample PKCS#11 file is setup to use a SafeNet USB token. – This samples applies a digital signature using a digital ID from the Windows certificate store.  Windows maintains a certificate and digital ID store.  Digital IDs in the store can come from certificate authorities, or can come from hardware tokens. – This samples adds the trusted certificates from the Windows certificate store to the list of certificates trusted by jPDFSecure. By default, jPDFSecure will trust root certificates that are shipped with Java, in its cacerts file, but a host application can manage what root certificates are trusted by jPDFSecure and can add trusted certificates from different sources, including the Windows certificate store. – This program demonstrates how to validate digital signatures in a PDF document. – This sample code demonstrates how to validate apply a digital signature with a digital timestamp to a PDF document.