org.apache.pdfbox.examples.signature
Class CreateSignature

java.lang.Object
  extended by org.apache.pdfbox.examples.signature.CreateSignature
All Implemented Interfaces:
org.apache.pdfbox.pdmodel.interactive.digitalsignature.SignatureInterface

public class CreateSignature
extends Object
implements org.apache.pdfbox.pdmodel.interactive.digitalsignature.SignatureInterface

This is an example for singing a pdf with bouncy castle.

A keystore can be created with the java keytool (e.g. keytool -genkeypair -storepass 123456 -storetype pkcs12 -alias test -validity 365 -v -keyalg RSA -keystore keystore.p12 )

Author:
Thomas Chojecki

Constructor Summary
CreateSignature(KeyStore keystore, char[] pin)
          Initialize the signature creator with a keystore (pkcs12) and pin that should be used for the signature.
 
Method Summary
static void main(String[] args)
           
 byte[] sign(InputStream content)
           SignatureInterface implementation.
 File signPDF(File document)
          Signs the given pdf file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CreateSignature

public CreateSignature(KeyStore keystore,
                       char[] pin)
Initialize the signature creator with a keystore (pkcs12) and pin that should be used for the signature.

Parameters:
keystore - is a pkcs12 keystore.
pin - is the pin for the keystore / private key
Method Detail

signPDF

public File signPDF(File document)
             throws IOException,
                    org.apache.pdfbox.exceptions.COSVisitorException,
                    org.apache.pdfbox.exceptions.SignatureException
Signs the given pdf file.

Parameters:
document - is the pdf document
Returns:
the signed pdf document
Throws:
IOException
org.apache.pdfbox.exceptions.COSVisitorException
org.apache.pdfbox.exceptions.SignatureException

sign

public byte[] sign(InputStream content)
            throws org.apache.pdfbox.exceptions.SignatureException,
                   IOException

SignatureInterface implementation.

This method will be called from inside of the pdfbox and create the pkcs7 signature. The given InputStream contains the bytes that are providen by the byte range.

This method is for internal use only.

Here the user should use his favorite cryptographic library and implement a pkcs7 signature creation.

Specified by:
sign in interface org.apache.pdfbox.pdmodel.interactive.digitalsignature.SignatureInterface
Throws:
org.apache.pdfbox.exceptions.SignatureException
IOException

main

public static void main(String[] args)
                 throws KeyStoreException,
                        NoSuchAlgorithmException,
                        CertificateException,
                        FileNotFoundException,
                        IOException,
                        org.apache.pdfbox.exceptions.COSVisitorException,
                        org.apache.pdfbox.exceptions.SignatureException
Throws:
KeyStoreException
NoSuchAlgorithmException
CertificateException
FileNotFoundException
IOException
org.apache.pdfbox.exceptions.COSVisitorException
org.apache.pdfbox.exceptions.SignatureException


Copyright © 2002-2014 The Apache Software Foundation. All Rights Reserved.