Class CreateSignature
- java.lang.Object
-
- org.apache.pdfbox.examples.signature.CreateSignatureBase
-
- org.apache.pdfbox.examples.signature.CreateSignature
-
- All Implemented Interfaces:
SignatureInterface
public class CreateSignature extends CreateSignatureBase
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
Constructors Constructor Description CreateSignature(java.security.KeyStore keystore, char[] pin)Initialize the signature creator with a keystore and certificate password.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidmain(java.lang.String[] args)voidsignDetached(java.io.File file)Signs the given PDF file.voidsignDetached(java.io.File inFile, java.io.File outFile)Signs the given PDF file.voidsignDetached(java.io.File inFile, java.io.File outFile, java.lang.String tsaUrl)Signs the given PDF file.voidsignDetached(PDDocument document, java.io.OutputStream output)private static voidusage()-
Methods inherited from class org.apache.pdfbox.examples.signature.CreateSignatureBase
getCertificateChain, isExternalSigning, setCertificateChain, setExternalSigning, setPrivateKey, setTsaUrl, sign
-
-
-
-
Constructor Detail
-
CreateSignature
public CreateSignature(java.security.KeyStore keystore, char[] pin) throws java.security.KeyStoreException, java.security.UnrecoverableKeyException, java.security.NoSuchAlgorithmException, java.security.cert.CertificateException, java.io.IOExceptionInitialize 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:
java.security.KeyStoreException- if the keystore has not been initialized (loaded)java.security.NoSuchAlgorithmException- if the algorithm for recovering the key cannot be foundjava.security.UnrecoverableKeyException- if the given password is wrongjava.security.cert.CertificateException- if the certificate is not valid as signing timejava.io.IOException- if no certificate could be found
-
-
Method Detail
-
signDetached
public void signDetached(java.io.File file) throws java.io.IOExceptionSigns the given PDF file. Alters the original file on disk.- Parameters:
file- the PDF file to sign- Throws:
java.io.IOException- if the file could not be read or written
-
signDetached
public void signDetached(java.io.File inFile, java.io.File outFile) throws java.io.IOExceptionSigns the given PDF file.- Parameters:
inFile- input PDF fileoutFile- output PDF file- Throws:
java.io.IOException- if the input file could not be read
-
signDetached
public void signDetached(java.io.File inFile, java.io.File outFile, java.lang.String tsaUrl) throws java.io.IOExceptionSigns the given PDF file.- Parameters:
inFile- input PDF fileoutFile- output PDF filetsaUrl- optional TSA url- Throws:
java.io.IOException- if the input file could not be read
-
signDetached
public void signDetached(PDDocument document, java.io.OutputStream output) throws java.io.IOException
- Throws:
java.io.IOException
-
main
public static void main(java.lang.String[] args) throws java.io.IOException, java.security.GeneralSecurityException- Throws:
java.io.IOExceptionjava.security.GeneralSecurityException
-
usage
private static void usage()
-
-