Class EGIZSignatureHandler

    • Constructor Detail

      • EGIZSignatureHandler

        public EGIZSignatureHandler​(EGIZSignatureHandler.Factory factory)
        Create a a new EGIZSignatureHandler from the specified Factory
    • Method Detail

      • createToken

        public java.lang.String createToken​(java.lang.String type,
                                            int line,
                                            int length)

        Create a new token to be inserted into the canvas. The token type must be one of "date" for the signature date, "serial" for the serial number, "parameter" for the parameter field, "value" for the signature value, "issuer" or "signer" for the signature issuer/signer, or "method" for the signature method. All these fields except for method can be split over multiple lines if necessary - the "line" parameter can range from 0 to 9.

        This method should be called by the populateCanvas method, which is passed a reference to this EGIZSignatureHandler for this reason.

        Parameters:
        type - one of "date", "serial", "signer", "issuer", "method", "parameter" or "value"
        line - the line number, from 0 to 9 (for type="method", this must be 0)
        length - the length of the field in the canvas
        Returns:
        the piece of text to be inserted into the canvas for later substitution
      • prepareToSign

        public void prepareToSign​(java.security.KeyStore keystore,
                                  java.lang.String alias,
                                  char[] password)
                           throws java.security.GeneralSecurityException
        Description copied from class: SignatureHandler

        This method initialized the handler using the specified values into a state where it's ready to sign. This method should be used to set any additional fields in the Signature dictionary, for example "Certs" for the Self-Sign handler.

        Those overriding this method must call super.prepareToSign() before doing anything else.

        Overrides:
        prepareToSign in class SignatureHandler
        Parameters:
        keystore - the KeyStore
        alias - which key to use
        password - the password to use to decode the key
        Throws:
        java.security.GeneralSecurityException
      • getPage

        public PDFPage getPage()
        Return the page this signature is on (if signed) or will be (if unsigned). Returns null if this cannot be determined.
        Since:
        2.13.1
      • getSignatureValue

        public byte[] getSignatureValue()
        Get the "Signature Value" of this signature.
      • setSignerInfo

        public void setSignerInfo​(java.lang.String value)
        Set the "Signer Information" field of this siganture. The supplied String may be split into multiple lines with "\n"
      • getCertificates

        public java.security.cert.X509Certificate[] getCertificates()
        Get the X.509 Certificates used to sign this Signature
      • getIssuerInfo

        public java.lang.String getIssuerInfo()
        Return the "Issuer Information" field of this siganture
      • setIssuerInfo

        public void setIssuerInfo​(java.lang.String value)
        Set the "Issuer Information" field of this siganture. The supplied String may be split into multiple lines with "\n"
      • setSignDate

        public void setSignDate​(java.util.Calendar calender)
        Set the time this signature was applied
      • getSignDate

        public java.util.Calendar getSignDate()
        Get the time this signature was applied
      • setSerialNumber

        public void setSerialNumber​(java.math.BigInteger serial)
        Set the "Serial Number" field of this Signature
      • getSerialNumber

        public java.math.BigInteger getSerialNumber()
        Get the "Serial Number" field of this Signature
      • getParameter

        public java.lang.String getParameter()
        Get the "Parameter" field of this Signature
      • setParameter

        public void setParameter​(java.lang.String value)
        Set the "Parameter" field of this Signature
      • getMessageDigest

        public java.security.MessageDigest getMessageDigest()
        Description copied from class: SignatureHandler
        Return a MessageDigest that will be used to calculate the digest of the PDF for signing. This message will be called before SignatureHandler.sign() - see the API docs for that method for more details.
        Specified by:
        getMessageDigest in class SignatureHandler
      • getVariables

        public java.util.Map<java.lang.String,​SignatureHandler.Placeholder> getVariables()
                                                                                        throws java.security.GeneralSecurityException
        Description copied from class: SignatureHandler

        Return the list of "variables" which will be set by the handler after the PDF is rendered. Entries in the returned map should have a String as a key and a SignatureHandler.Placeholder as a value. These placeholders will be inserted into the PDF at the correct points.

        For most SignatureHandlers, the only variables are the "ByteRange" and "Contents" array containing the signature token, which is what this method returns (it may be overridden if more variables are required).

        This method was updated for a new signing architecture in release 2.11.12.

        Overrides:
        getVariables in class SignatureHandler
        Returns:
        a Map containing the variables to be substituted into the PDF during signing
        Throws:
        java.security.GeneralSecurityException
        See Also:
        AcrobatSignatureHandlerFactory.setContentSize(int)
      • preDigest

        public void preDigest​(long filelength,
                              java.util.Map<java.lang.String,​SignatureHandler.Placeholder> variables)
                       throws java.io.IOException,
                              java.security.GeneralSecurityException,
                              java.security.cert.CertificateException
        Description copied from class: SignatureHandler
        Update any Variables that need to be updated before the Digest is calculated (eg ByteRange).
        Overrides:
        preDigest in class SignatureHandler
        Parameters:
        filelength - the length of the PDF file, in bytes
        variables - the Map of variables, ordered by their position in the file.
        Throws:
        java.io.IOException
        java.security.GeneralSecurityException
        java.security.cert.CertificateException
      • postDigest

        public void postDigest​(long filelength,
                               java.util.Map<java.lang.String,​SignatureHandler.Placeholder> variables)
                        throws java.lang.Exception
        Description copied from class: SignatureHandler
        Update any Variables that need to be updated after the Digest is calculated (eg Contents).
        Overrides:
        postDigest in class SignatureHandler
        Parameters:
        filelength - the length of the PDF file, in bytes
        variables - the Map of variables, ordered by their position in the file.
        Throws:
        java.lang.Exception
      • verify

        public boolean verify​(java.io.InputStream in)
                       throws java.io.IOException,
                              java.security.GeneralSecurityException
        Description copied from class: SignatureHandler
        Return a boolean indicating whether or not the signature handler can verify the specified InputStream.
        Specified by:
        verify in class SignatureHandler
        Returns:
        true if the signature matches the specified InputStream
        Throws:
        java.io.IOException - if the InputStream cannot be read
        java.security.GeneralSecurityException - if the signature cannot be verified for some cryptographic reason