org.apache.pdfbox.examples.signature
Class CreateVisibleSignature

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

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

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

And also you can create visible signature too

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:
Vakhtang koroghlishvili (Gogebashvili)

Constructor Summary
CreateVisibleSignature(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)
          Arguments are [0] key store [1] pin [2] document that will be signed [3] image of visible signature
 byte[] sign(InputStream content)
           SignatureInterface implementation.
 File signPDF(File document, org.apache.pdfbox.pdmodel.interactive.digitalsignature.visible.PDVisibleSigProperties signatureProperties)
          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

CreateVisibleSignature

public CreateVisibleSignature(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,
                    org.apache.pdfbox.pdmodel.interactive.digitalsignature.visible.PDVisibleSigProperties signatureProperties)
             throws IOException,
                    org.apache.pdfbox.exceptions.COSVisitorException,
                    org.apache.pdfbox.exceptions.SignatureException
Signs the given pdf file.

Parameters:
document - is the pdf document
signatureProperties -
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
Arguments are [0] key store [1] pin [2] document that will be signed [3] image of visible signature

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.