Class CreateSignature
java.lang.Object
org.apache.pdfbox.examples.signature.CreateSignatureBase
org.apache.pdfbox.examples.signature.CreateSignature
- All Implemented Interfaces:
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 -
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(PDDocument document, OutputStream output) private static voidusage()Methods inherited from class org.apache.pdfbox.examples.signature.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
- Throws:
IOException
-
main
- Throws:
IOExceptionGeneralSecurityException
-
usage
private static void usage()
-