Class CreateSignatureBase

    • Constructor Summary

      Constructors 
      Constructor Description
      CreateSignatureBase​(java.security.KeyStore keystore, char[] pin)
      Initialize the signature creator with a keystore (pkcs12) and pin that should be used for the signature.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.security.cert.Certificate[] getCertificateChain()  
      boolean isExternalSigning()  
      void setCertificateChain​(java.security.cert.Certificate[] certificateChain)  
      void setExternalSigning​(boolean externalSigning)
      Set if external signing scenario should be used.
      void setPrivateKey​(java.security.PrivateKey privateKey)  
      void setTsaUrl​(java.lang.String tsaUrl)  
      byte[] sign​(java.io.InputStream content)
      SignatureInterface sample implementation.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • privateKey

        private java.security.PrivateKey privateKey
      • certificateChain

        private java.security.cert.Certificate[] certificateChain
      • tsaUrl

        private java.lang.String tsaUrl
      • externalSigning

        private boolean externalSigning
    • Constructor Detail

      • CreateSignatureBase

        public CreateSignatureBase​(java.security.KeyStore keystore,
                                   char[] pin)
                            throws java.security.KeyStoreException,
                                   java.security.UnrecoverableKeyException,
                                   java.security.NoSuchAlgorithmException,
                                   java.io.IOException,
                                   java.security.cert.CertificateException
        Initialize the signature creator with a keystore (pkcs12) and pin that should be used for the signature.
        Parameters:
        keystore - is a pkcs12 keystore.
        pin - is the pin for the keystore / private 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

      • setPrivateKey

        public final void setPrivateKey​(java.security.PrivateKey privateKey)
      • setCertificateChain

        public final void setCertificateChain​(java.security.cert.Certificate[] certificateChain)
      • getCertificateChain

        public java.security.cert.Certificate[] getCertificateChain()
      • setTsaUrl

        public void setTsaUrl​(java.lang.String tsaUrl)
      • sign

        public byte[] sign​(java.io.InputStream content)
                    throws java.io.IOException
        SignatureInterface sample implementation.

        This method will be called from inside of the pdfbox and create the PKCS #7 signature. The given InputStream contains the bytes that are given by the byte range.

        This method is for internal use only.

        Use your favorite cryptographic library to implement PKCS #7 signature creation. If you want to create the hash and the signature separately (e.g. to transfer only the hash to an external application), read this answer or this answer.

        Specified by:
        sign in interface SignatureInterface
        Parameters:
        content - is the content as a (Filter)InputStream
        Returns:
        signature as a byte array
        Throws:
        java.io.IOException
      • setExternalSigning

        public void setExternalSigning​(boolean externalSigning)
        Set if external signing scenario should be used. If false, SignatureInterface would be used for signing.

        Default: false

        Parameters:
        externalSigning - true if external signing should be performed
      • isExternalSigning

        public boolean isExternalSigning()