Top Description Constructors Methods
org.apache.pdfbox.examples.signature

public Class CreateSignature

extends CreateSignatureBase
Class Inheritance
Imports
java.io.File, .FileInputStream, .FileNotFoundException, .FileOutputStream, .IOException, .InputStream, .OutputStream, java.security.GeneralSecurityException, .KeyStore, .KeyStoreException, .NoSuchAlgorithmException, .UnrecoverableKeyException, java.security.cert.CertificateException, java.util.Calendar, org.apache.pdfbox.Loader, org.apache.pdfbox.pdmodel.PDDocument, org.apache.pdfbox.pdmodel.interactive.digitalsignature.ExternalSigningSupport, .PDSignature, .SignatureOptions

An example for signing a PDF with bouncy castle. A keystore can be created with the java keytool, for example: keytool -genkeypair -storepass 123456 -storetype pkcs12 -alias test -validity 365 -v -keyalg RSA -keystore keystore.p12
Authors
Thomas Chojecki, Vakhtang Koroghlishvili, John Hewson

Constructor Summary

AccessConstructor and Description
public
CreateSignature(KeyStore
the pkcs12 keystore containing the signing certificate
keystore
,
char[]
the password for recovering the key
pin
)

Initialize the signature creator with a keystore and certificate password.

Method Summary

Modifier and TypeMethod and Description
public static void
main(String[] args)

public void
signDetached(File
the PDF file to sign
file
)

Signs the given PDF file.

public void
signDetached(File
input PDF file
inFile
,
File
output PDF file
outFile
)

Signs the given PDF file.

public void
signDetached(File
input PDF file
inFile
,
File
output PDF file
outFile
,
String
optional TSA url
tsaUrl
)

Signs the given PDF file.

public void
private static void
Inherited from org.apache.pdfbox.examples.signature.CreateSignatureBase:
getCertificateChainisExternalSigningsetCertificateChainsetExternalSigningsetPrivateKeysetTsaUrlsign

Constructor Detail

CreateSignatureback to summary
public CreateSignature(KeyStore keystore, char[] pin) throws KeyStoreException, UnrecoverableKeyException, NoSuchAlgorithmException, CertificateException, IOException

Initialize the signature creator with a keystore and certificate password.

Parameters
keystore:KeyStore

the pkcs12 keystore containing the signing certificate

pin:char[]

the password for recovering the key

Exceptions
KeyStoreException:
if the keystore has not been initialized (loaded)
UnrecoverableKeyException:
if the given password is wrong
NoSuchAlgorithmException:
if the algorithm for recovering the key cannot be found
CertificateException:
if the certificate is not valid as signing time
IOException:
if no certificate could be found

Method Detail

mainback to summary
public static void main(String[] args) throws IOException, GeneralSecurityException
signDetachedback to summary
public void signDetached(File file) throws IOException

Signs the given PDF file. Alters the original file on disk.

Parameters
file:File

the PDF file to sign

Exceptions
IOException:
if the file could not be read or written
signDetachedback to summary
public void signDetached(File inFile, File outFile) throws IOException

Signs the given PDF file.

Parameters
inFile:File

input PDF file

outFile:File

output PDF file

Exceptions
IOException:
if the input file could not be read
signDetachedback to summary
public void signDetached(File inFile, File outFile, String tsaUrl) throws IOException

Signs the given PDF file.

Parameters
inFile:File

input PDF file

outFile:File

output PDF file

tsaUrl:String

optional TSA url

Exceptions
IOException:
if the input file could not be read
signDetachedback to summary
public void signDetached(PDDocument document, OutputStream output) throws IOException
usageback to summary
private static void usage()