DigiStamp.com

com.digistamp.pdf.test
Class PdfSignerDemo

java.lang.Object
  extended by com.digistamp.pdf.test.PdfSignerDemo

public class PdfSignerDemo
extends java.lang.Object

Demonstrate creating a PKI digital signature of a PDF document and then time-stamp that signature.
Demo dependencies:

  1. user supplies existing PDF file that is not currently signed.
  2. supply a PKCS12 (.pfx) key store with public key certificate
  3. account at DigiStamp time stamps servers
  4. Access to Java Jar libraries from iText, BouncyCastle and DigiStamp

Output is a signed and timestamped PDF copy of your input file. The type of PDF signature created is 'certifying' signature.

This demo program expect user supplied parameters to specify the signing credentials (a key store) and access to an Internet-based time stamp server.

Signing credentials are created using a certificate authority. See information here: http://www.digistamp.com/helps/keySetup.htm

An alternative for signing credential is making key-pair for testing:

keytool -genkey -v -alias abc -dname "cn=A Person, o=Test Org, L=A Location, S=A State, C=MY" -keypass 7777777 -keystore GenTest.p12 -storetype PKCS12 -keyalg RSA -keysize 2048 -storepass 7777777 -validity 720

DigiStamp configuration properties. An example configuration file name "DigiStamp.properties" was provided with the distribution; you will need to add your account number and password to the file "DigiStamp.properties". More configuration details are here: TSAConfig.

An optional authentication step can be performed within the time stamp request processing: is the public key of the time stamp certificate trusted? This is a recommended validation to be performed. You will need to supply the trusted root certificate in a file or install the certificate to the Java libraries trusted keystore. See method initializeDigistamp(String) below.


Constructor Summary
PdfSignerDemo()
           
 
Method Summary
static TSAClientDigiStamp initializeDigistamp(java.lang.String digistampPropertiesPath)
          DigiStamp client library needs configuration data like which TSA servers to use and the account and password information.
static void loggerSetForTesting()
          Logger messages can be displayed.
static void main(java.lang.String[] args)
          Command line interface to create a signed PDF with a valid time-stamp.
 void setAppearance(com.lowagie.text.pdf.PdfSignatureAppearance sap)
          Setup the appearance of the signature within the PDF file.
 void setContentEst(int lazyInitContentEst)
          Estimate signature size, creating a 'fake' one using fake data and the constant length of a SHA1.
 void setSks(SignerKeystore sks)
          The keystore with credentials to sign the PDF.
 void setTsa(com.lowagie.text.pdf.TSAClient tsa)
          The object responsible for retrieving the RFC 3161 timeStampToken.
 void signPDF(java.io.InputStream srcInputStream, java.io.OutputStream dstOutputStream, com.lowagie.text.pdf.TSAClient tsc)
          Demo using iText to digitally sign PDF document with a valid time-stamp.
 void signPDF(java.lang.String srcFile, java.lang.String dstFile)
          Read PDF from input file and output new PDF that is signed and time stamped.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PdfSignerDemo

public PdfSignerDemo()
Method Detail

initializeDigistamp

public static TSAClientDigiStamp initializeDigistamp(java.lang.String digistampPropertiesPath)
                                              throws java.io.FileNotFoundException,
                                                     java.io.IOException,
                                                     java.security.cert.CertificateException
DigiStamp client library needs configuration data like which TSA servers to use and the account and password information. You could build this set of properties with the configuration data in a variety a ways, demonstrated here is reading properties from a file.

Optional, an additional authentication step can be performed within the DigiStamp time stamp request processing: is the public key of the time stamp certificate trusted? This is a recommended validation to be performed. see: TSAClient.setTrustedRootCertificate(X509Certificate)

Parameters:
digistampPropertiesPath - - file name
Throws:
java.io.FileNotFoundException
java.io.IOException
java.security.cert.CertificateException

loggerSetForTesting

public static void loggerSetForTesting()
Logger messages can be displayed. Convenience method to set the 'com.digistamp' logger to display actions as the time stamp request is sent over the Internet and response received.


main

public static void main(java.lang.String[] args)
Command line interface to create a signed PDF with a valid time-stamp.

Parameters:
args - keyStorePath keyStorePassWord digistampPropertiesPath PDFfile {PDFfile} {PDFfile}...

setAppearance

public void setAppearance(com.lowagie.text.pdf.PdfSignatureAppearance sap)
Setup the appearance of the signature within the PDF file.

Parameters:
sap - PdfSignatureAppearance

setContentEst

public void setContentEst(int lazyInitContentEst)
Estimate signature size, creating a 'fake' one using fake data and the constant length of a SHA1.


setSks

public void setSks(SignerKeystore sks)
The keystore with credentials to sign the PDF.

Parameters:
sks -

setTsa

public void setTsa(com.lowagie.text.pdf.TSAClient tsa)
The object responsible for retrieving the RFC 3161 timeStampToken.

Parameters:
tsa -

signPDF

public void signPDF(java.io.InputStream srcInputStream,
                    java.io.OutputStream dstOutputStream,
                    com.lowagie.text.pdf.TSAClient tsc)
Demo using iText to digitally sign PDF document with a valid time-stamp. Demo dependencies: SignerKeystore - interface providing signing certificate access SignerKeystorePKCS12 - implementation importing PKCS12 (.pfx) certificate

originated from work by Martin Brunecky dated Jul 25, 2007; 01:13pm from the itext-questions@lists.sourceforge.net mailing list

Parameters:
srcInputStream -
dstOutputStream -
tsc -

signPDF

public void signPDF(java.lang.String srcFile,
                    java.lang.String dstFile)
             throws java.lang.Exception
Read PDF from input file and output new PDF that is signed and time stamped.

Parameters:
srcFile -
dstFile -
Throws:
java.lang.Exception

Copyright 2000-2010 DigiStamp, Inc.