Class 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 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.IOException
        Initialize the signature creator with a keystore and certificate password.
        Parameters:
        keystore - the pkcs12 keystore containing the signing certificate
        pin - 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 found
        java.security.UnrecoverableKeyException - if the given password is wrong
        java.security.cert.CertificateException - if the certificate is not valid as signing time
        java.io.IOException - if no certificate could be found
    • Method Detail

      • signDetached

        public void signDetached​(java.io.File file)
                          throws java.io.IOException
        Signs 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.IOException
        Signs the given PDF file.
        Parameters:
        inFile - input PDF file
        outFile - 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.IOException
        Signs the given PDF file.
        Parameters:
        inFile - input PDF file
        outFile - output PDF file
        tsaUrl - 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.IOException
        java.security.GeneralSecurityException
      • usage

        private static void usage()