Class CreateSignature
java.lang.Object
org.apache.pdfbox.examples.signature.CreateSignatureBase
org.apache.pdfbox.examples.signature.CreateSignature
- All Implemented Interfaces:
org.apache.pdfbox.pdmodel.interactive.digitalsignature.SignatureInterface
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 - Author:
- Thomas Chojecki, Vakhtang Koroghlishvili, John Hewson
-
Constructor Summary
ConstructorsConstructorDescriptionCreateSignature(KeyStore keystore, char[] pin) Initialize the signature creator with a keystore and certificate password. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidvoidsignDetached(File file) Signs the given PDF file.voidsignDetached(File inFile, File outFile) Signs the given PDF file.voidsignDetached(File inFile, File outFile, String tsaUrl) Signs the given PDF file.voidsignDetached(org.apache.pdfbox.pdmodel.PDDocument document, OutputStream output) Methods inherited from class CreateSignatureBase
getCertificateChain, isExternalSigning, setCertificateChain, setExternalSigning, setPrivateKey, setTsaUrl, sign
-
Constructor Details
-
CreateSignature
public CreateSignature(KeyStore keystore, char[] pin) throws KeyStoreException, UnrecoverableKeyException, NoSuchAlgorithmException, CertificateException, IOException Initialize the signature creator with a keystore and certificate password.- Parameters:
keystore- the pkcs12 keystore containing the signing certificatepin- the password for recovering the key- Throws:
KeyStoreException- if the keystore has not been initialized (loaded)NoSuchAlgorithmException- if the algorithm for recovering the key cannot be foundUnrecoverableKeyException- if the given password is wrongCertificateException- if the certificate is not valid as signing timeIOException- if no certificate could be found
-
-
Method Details
-
signDetached
Signs the given PDF file. Alters the original file on disk.- Parameters:
file- the PDF file to sign- Throws:
IOException- if the file could not be read or written
-
signDetached
Signs the given PDF file.- Parameters:
inFile- input PDF fileoutFile- output PDF file- Throws:
IOException- if the input file could not be read
-
signDetached
Signs the given PDF file.- Parameters:
inFile- input PDF fileoutFile- output PDF filetsaUrl- optional TSA url- Throws:
IOException- if the input file could not be read
-
signDetached
public void signDetached(org.apache.pdfbox.pdmodel.PDDocument document, OutputStream output) throws IOException - Throws:
IOException
-
main
- Throws:
IOExceptionGeneralSecurityException
-