Class Signature


  • public class Signature
    extends Object
    A class that represents a PDF signing certificate (.PFX or .p12) format which can be used to digitally sign a PDF. This protecting it from alteration.
    • Constructor Detail

      • Signature

        public Signature​(String filePathToCertificate,
                         String password)
                  throws IOException
        Initializes a new instance of the Signature class using a .pfx or .p12 digital signature file.
        Parameters:
        filePathToCertificate - The file path to certificate.
        password - The certificate's password.
        Throws:
        IOException - if an I/O error occurs reading from the stream
      • Signature

        public Signature​(Path filePathToCertificate,
                         String password)
                  throws IOException
        Initializes a new instance of the Signature class using a .pfx or .p12 digital signature file.
        Parameters:
        filePathToCertificate - The file path to certificate.
        password - The certificate's password.
        Throws:
        IOException - if an I/O error occurs reading from the stream
      • Signature

        public Signature​(byte[] certificateRawData,
                         String password)
        Initializes a new instance of the Signature class.
        Parameters:
        certificateRawData - The certificate as a binary data (byte array).
        password - The certificate's password.
      • Signature

        public Signature​(byte[] certificateRawData,
                         String password,
                         Instant signatureDate,
                         byte[] signatureImage,
                         String signingContact,
                         String signingLocation,
                         String signingReason,
                         Rectangle signatureImageRectangle)
        Initializes a new instance of the Signature class.
        Parameters:
        certificateRawData - the certificate as a binary data (byte array).
        password - the certificate's password.
        signatureDate - the date and time of the digital signature. If left null, the current time is captured when the signature is applied and used as the signing date.
        signatureImage - a visual image for the sign, often a PNG of a human signature or company stamp (optional).

        This appends a visual signature in addition to cryptographic signing.

        signingContact - the contact person or email address for signing related inquiries (optional).
        signingLocation - the physical location the PDF was signed (optional).
        signingReason - the reason the PDF was signed (optional).
    • Method Detail

      • getCertificateRawData

        public byte[] getCertificateRawData()
        Get certificate raw data byte [ ].
        Returns:
        the byte [ ]
      • setCertificateRawData

        public void setCertificateRawData​(byte[] certificateRawData)
        Sets certificate raw data.
        Parameters:
        certificateRawData - the certificate raw data
      • getSignatureDate

        public Instant getSignatureDate()
        Gets signature date. The date and time of the digital signature. If left null, the current time is captured when the signature is applied and used as the signing date.
        Returns:
        the signature date
      • setSignatureDate

        public void setSignatureDate​(Instant signatureDate)
        Sets signature date. The date and time of the digital signature. If left null, the current time is captured when the signature is applied and used as the signing date.
        Parameters:
        signatureDate - the signature date
      • getSignatureImage

        public byte[] getSignatureImage()
        Get signature image. A visual image for the sign, often a PNG of a human signature or company stamp (optional).

        This appends a visual signature in addition to cryptographic signing.

        Returns:
        the image byte[]
      • getSignatureImageRectangle

        public Rectangle getSignatureImageRectangle()
        Get signature image Rectangle. A position of visual image for the sign

        Returns:
        Rectangle
      • setSignatureImageRectangle

        public void setSignatureImageRectangle​(Rectangle rectangle)
        Set signature image Rectangle. A position of visual image for the sign

      • setSignatureImage

        public void setSignatureImage​(byte[] signatureImage,
                                      Rectangle rectangle)
        Sets signature image. A visual image for the sign, often a PNG of a human signature or company stamp (optional).

        This appends a visual signature in addition to cryptographic signing.

        Parameters:
        signatureImage - the signature image
        rectangle - Rectangle to display image
      • getSigningContact

        public String getSigningContact()
        Gets signing contact. The contact person or email address for signing related inquiries (optional).
        Returns:
        the signing contact
      • setSigningContact

        public void setSigningContact​(String signingContact)
        Sets signing contact. The contact person or email address for signing related inquiries (optional).
        Parameters:
        signingContact - the signing contact
      • getSigningLocation

        public String getSigningLocation()
        Gets signing location. The physical location the PDF was signed (optional).
        Returns:
        the signing location
      • setSigningLocation

        public void setSigningLocation​(String signingLocation)
        Sets signing location. The physical location the PDF was signed (optional).
        Parameters:
        signingLocation - the signing location
      • getSigningReason

        public String getSigningReason()
        Gets signing reason. The reason the PDF was signed (optional).
        Returns:
        the signing reason
      • setSigningReason

        public void setSigningReason​(String signingReason)
        Sets signing reason. The reason the PDF was signed (optional).
        Parameters:
        signingReason - the signing reason
      • getPassword

        public String getPassword()
        Gets password.
        Returns:
        the password
      • setPassword

        public void setPassword​(String password)
        Sets password.
        Parameters:
        password - the password
      • getTimeStampUrl

        public String getTimeStampUrl()
        Gets Url to be used when time-stamping the signature
        Returns:
        the timestamp url
      • setTimeStampUrl

        public void setTimeStampUrl​(String timeStampUrl)
        Sets Url to be used when time-stamping the signature
        Parameters:
        timeStampUrl - the timestamp url
      • getSignatureFieldName

        public String getSignatureFieldName()
        Gets the name (/T) of the existing signature field this signature is applied into.
        Returns:
        the field name, or null (default) to append a new signature field
      • setSignatureFieldName

        public void setSignatureFieldName​(String signatureFieldName)
        Sets the name (/T) of an existing, unsigned signature field to sign into, instead of appending a new signature field. Useful for forms with pre-placed signature blocks. Signing throws if no unsigned field with that name exists (or every field with that name is already signed). null, empty or whitespace-only means the default behavior of appending a new field.

        Cannot be combined with a signature image: applying an image rewrites the field's rectangle and page, which would move the pre-placed signature block.

        Parameters:
        signatureFieldName - the field name, or null
      • getSignatureHashAlgorithm

        public SignatureHashAlgorithms getSignatureHashAlgorithm()
        Gets the hashing algorithm used to compute the PKCS#7/CMS signature digest.
        Returns:
        the signature hash algorithm
      • setSignatureHashAlgorithm

        public void setSignatureHashAlgorithm​(SignatureHashAlgorithms signatureHashAlgorithm)
        Sets the hashing algorithm used to compute the PKCS#7/CMS signature digest. Defaults to SignatureHashAlgorithms.SHA256. Must not be null: the sign and save paths dereference it unconditionally, and a null would otherwise surface as a delayed NullPointerException.
        Parameters:
        signatureHashAlgorithm - the signature hash algorithm (non-null)
        Throws:
        IllegalArgumentException - if signatureHashAlgorithm is null
      • getTimestampHashAlgorithm

        public TimestampHashAlgorithms getTimestampHashAlgorithm()
        Gets the algorithm requested from the RFC 3161 time-stamping server for the message imprint.
        Returns:
        the timestamp hash algorithm
      • setTimestampHashAlgorithm

        public void setTimestampHashAlgorithm​(TimestampHashAlgorithms timestampHashAlgorithm)
        Sets the algorithm requested from the RFC 3161 time-stamping server for the message imprint. Defaults to TimestampHashAlgorithms.SHA256. Must not be null: the sign and save paths dereference it unconditionally, and a null would otherwise surface as a delayed NullPointerException.
        Parameters:
        timestampHashAlgorithm - the timestamp hash algorithm (non-null)
        Throws:
        IllegalArgumentException - if timestampHashAlgorithm is null
      • getInternalIndex

        public int getInternalIndex()
        Internal using only