com.crionics.jpdf.forms
Class SignatureField

java.lang.Object
  extended by PdfObjectContainer
      extended by com.crionics.jpdf.forms.AbstractField
          extended by com.crionics.jpdf.forms.SignatureField

public class SignatureField
extends AbstractField

Representation of a signature form field. This class contains all the methods to validate and sign PDF Signatures fields.


Method Summary
 void addDuplicatedAppearance(int pageindex, java.awt.Point position)
          This method can be used to duplicate the Visual appearance of the signature on any pages of the current Document Instance.
static SignatureField createInstance(PdfDocument doc, java.lang.String name)
          Create a Invisible Signature in the specified document.
static SignatureField createInstance(PdfDocument doc, java.lang.String name, int pageIndex, java.awt.Rectangle rect)
          Create a Blank Signature in the specified document.
 java.security.cert.X509Certificate[] getCertificateChain()
          Returns the certificate chain.
 java.lang.String getContactInfo()
          Returns the signer's contact information, empty if not set
 byte[] getDigest()
          Returns the signature digest, result of the signature calculation.
 java.io.InputStream getInputStream()
          Returns an inputstrean on the data part of the signature calculation.
 java.lang.String getLocation()
          Returns the signer's location, empty if not set
 java.lang.String getReason()
          Returns the signer's reason to sign the document, empty if not set
 java.lang.String getSignerName()
          Returns the name of the signer, empty if not set
 boolean isBlank()
          returns true if the signature has never been signed.
 boolean isLocked()
          returns true if the signature is locked and cannot be changed.
 void setReason(java.lang.String reason)
          As described in the PDF spec,
 void setSignatureAppearance(SignatureAppearance app)
          Sets the Object which will be used to construct the visual appearance of the Signature Form Field in the document after being signed.
 void sign(CustomSigner signer)
          Signs an existing signature field using the given custom signer.
 void sign(java.security.PrivateKey privateKey, java.security.cert.Certificate[] chain)
          Signs an existing signature field using the given private key and certification chain.
 ValidationResults validate()
          Validates the signature using the default validators:
The byterange validity is checked to certify that the signature covers the whole documents (excluding the signature content).
 
Methods inherited from class com.crionics.jpdf.forms.AbstractField
getAssociatedPageIndex, getBorderColor, getBorderStyle, getBorderWidth, getFillColor, getName, getOrientation, getPosition, getTextColor, getTextFont, getTextSize, getToolTip, isHidden, isPrintable, isReadOnly, setBorderColor, setBorderStyle, setBorderWidth, setFillColor, setHidden, setOrientation, setPosition, setPrintable, setReadOnly, setTextColor, setTextFont, setTextFont, setTextSize, setToolTip
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createInstance

public static SignatureField createInstance(PdfDocument doc,
                                            java.lang.String name)
                                     throws PdfException,
                                            java.io.IOException
Create a Invisible Signature in the specified document.

Parameters:
doc - The Document where the Signature should be created.
name - The Name of the Signature Form Field.
Returns:
The Signature Field Created.
Throws:
PdfException - If a problem occurred while parsing the document.
java.io.IOException - If a problem occurred while parsing the file.

createInstance

public static SignatureField createInstance(PdfDocument doc,
                                            java.lang.String name,
                                            int pageIndex,
                                            java.awt.Rectangle rect)
                                     throws PdfException,
                                            java.io.IOException
Create a Blank Signature in the specified document.

Parameters:
doc - The Document where the Signature should be created.
name - The Name of the Signature Form Field.
pageIndex - The Index of the page where the Form Field should be created.
rect - The Position and Size of the Form Field on the specified page.
Returns:
The Signature Field Created.
Throws:
PdfException - If a problem occured while parsing the document.
java.io.IOException - If a problem occured while parsing the file.

addDuplicatedAppearance

public void addDuplicatedAppearance(int pageindex,
                                    java.awt.Point position)
                             throws java.io.IOException,
                                    PdfException
This method can be used to duplicate the Visual appearance of the signature on any pages of the current Document Instance. Note 1: This Method can not be called after the Signature has been signed. Note 2: This Method can be called as many times as necessary when adding duplication on different pages.

Parameters:
pageindex - The index of the page where the Visual Appearance should be added
position - The Top Left Coordinate of the Signature Visual Appearance in reference to the Top Left corner of the requested page.
Throws:
PdfException - If a problem occurred while parsing the document.
java.io.IOException - If a problem occurred while parsing the file.

getCertificateChain

public java.security.cert.X509Certificate[] getCertificateChain()
                                                         throws PdfException,
                                                                java.io.IOException
Returns the certificate chain. Element 0 is the signing certificate. The method can only be used if the signature is not BLANK or PENDING.

Returns:
the certificate chain. element 0 is the signing certificate
Throws:
PdfException - io issue
java.io.IOException - pdf related issue

getContactInfo

public java.lang.String getContactInfo()
                                throws java.io.IOException,
                                       PdfException
Returns the signer's contact information, empty if not set

Returns:
the signer's contact information
Throws:
java.io.IOException - io problem
PdfException - if signature is blank

getDigest

public byte[] getDigest()
                 throws PdfException,
                        java.io.IOException
Returns the signature digest, result of the signature calculation. Depending on the signature type - this is typically a DER encoded PKCS#1 or a PKCS#7 octet byte array. The method can only be used if the signature is not BLANK or PENDING.

Returns:
the encoded PDF signature, result of the signature calculation.
Throws:
PdfException - pdf related exception
PdfSignatureException - pdf errors more specific to signature generation
java.io.IOException - io/cache issues

getInputStream

public java.io.InputStream getInputStream()
                                   throws PdfException,
                                          java.io.IOException
Returns an inputstrean on the data part of the signature calculation. The methods takes in consideration the type of signature (byterange or digested) as well as the "holes" part of the /Range entry. The method can only be used if the signature is not BLANK or PENDING.

Returns:
an inputstrean on the data part of the signature calculation.
Throws:
PdfException - io issue
java.io.IOException - pdf related issue

getLocation

public java.lang.String getLocation()
                             throws java.io.IOException,
                                    PdfException
Returns the signer's location, empty if not set

Returns:
the signer's location
Throws:
java.io.IOException - io problem
PdfException - if signature is blank

getReason

public java.lang.String getReason()
                           throws java.io.IOException,
                                  PdfException
Returns the signer's reason to sign the document, empty if not set

Returns:
the signer's reason to sign the document
Throws:
java.io.IOException - io problem
PdfException - if signature is blank

getSignerName

public java.lang.String getSignerName()
                               throws java.io.IOException,
                                      PdfException
Returns the name of the signer, empty if not set

Returns:
the name of the signer
Throws:
java.io.IOException - io problem
PdfException - if signature is blank

isBlank

public boolean isBlank()
                throws PdfException,
                       java.io.IOException
returns true if the signature has never been signed.

Returns:
true if the signature has never been signed.
Throws:
java.io.IOException - io issue
PdfException - pdf related issue

isLocked

public boolean isLocked()
                 throws PdfException,
                        java.io.IOException
returns true if the signature is locked and cannot be changed.

Returns:
true if the signature is locked.
Throws:
java.io.IOException - io issue
PdfException - pdf related issue

setReason

public void setReason(java.lang.String reason)
               throws java.io.IOException,
                      PdfException
As described in the PDF spec,

Parameters:
reason - the reason to sign this document
Throws:
java.io.IOException - io issue
PdfException - pdf related issue

setSignatureAppearance

public void setSignatureAppearance(SignatureAppearance app)
                            throws java.io.IOException,
                                   PdfException
Sets the Object which will be used to construct the visual appearance of the Signature Form Field in the document after being signed.

Parameters:
app - The appearance setup to use.
Throws:
java.io.IOException - Raised if a problem occured while reading the file.
PdfException - Raised if a problem occured while parsing the file.

sign

public void sign(CustomSigner signer)
          throws PdfException,
                 java.io.IOException
Signs an existing signature field using the given custom signer. The signer name, contact info, date, location are automatically filled from the custom signer signing certificate (getCertificateChain()[0]). It is important to note that once a signature is signed, it must be saved before any validation can occur.

Parameters:
signer -
Throws:
PdfException - if the signature is locked
java.io.IOException - io/cache issues

sign

public void sign(java.security.PrivateKey privateKey,
                 java.security.cert.Certificate[] chain)
          throws PdfException,
                 java.io.IOException
Signs an existing signature field using the given private key and certification chain. The signer name, contact info, date, location are automatically filled from the signing certificate (cahin[0]). It is important to note that once a signature is signed, it must be saved before any validation can occur.

Parameters:
privateKey - private key used to sign this document
chain - certification path associated with the private key
Throws:
PdfException - if the signature is locked
java.io.IOException

validate

public ValidationResults validate()
                           throws java.io.IOException,
                                  PdfException
Validates the signature using the default validators:
The byterange validity is checked to certify that the signature covers the whole documents (excluding the signature content).
The signature validity is checked to certify the content was not violated.
The signature dates are check to validate their validity at the time the document was signed.
The certificate itself is checked to make sure it wasn't altered by third parties.

Returns:
a list of results in a ValidationResults list
Throws:
java.io.IOException - io issue
PdfException - if the signature is blank or pending


Copyright © 1999-2007 Crionics. All Rights Reserved.