• jPDFSecure



    Encrypt and digitally sign PDF documents, as well as set permissions and passwords.


jPDFSecure Source Code Samples

Following are a number of Java samples that use jPDFSecure and some of its features:

SignDocument.java – 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

SetPermissions.java – This program encrypts a document and restricts permissions to only allow printing.

ListPermissions.java – This program lists the encryption and permissions settings of a PDF document.

ClearSecurity.java – This program clears the encryption and allows all permissions in a PDF document.

CustomSignature.java – 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.

SignWithPKCS11.java – 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.

SignWithWindowsID.java – 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.

TrustWindowsRootCAs.java – 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.

VerifySignatures.java – This program demonstrates how to validate digital signatures in a PDF document.

SignWithTimestampServer.java – This sample code demonstrates how to validate apply a digital signature with a digital timestamp to a PDF document.

SignTwice.java – This sample code demonstrates how to apply two digital signatures to a PDF document. One has to sign and reload before applying the second signature.