org.apache.pdfbox.pdmodel.interactive.digitalsignature

## Class PDSignature

- java.lang.Object
- - org.apache.pdfbox.pdmodel.interactive.digitalsignature.PDSignature

All Implemented Interfaces:
  COSObjectable

    public class PDSignature
    extends Object
    implements COSObjectable

This represents a digital signature that can be attached to a document. To learn more about digital signatures, read Digital Signatures in a PDF by Adobe.

Author:
  Ben Litchfield, Thomas Chojecki

### Field Summary

Fields
`static COSName` `FILTER_ADOBE_PPKLITE` A signature filter value.
`static COSName` `FILTER_CICI_SIGNIT` A signature filter value.
`static COSName` `FILTER_ENTRUST_PPKEF` A signature filter value.
`static COSName` `FILTER_VERISIGN_PPKVS` A signature filter value.
`static COSName` `SUBFILTER_ADBE_PKCS7_DETACHED` A signature subfilter value.
`static COSName` `SUBFILTER_ADBE_PKCS7_SHA1` A signature subfilter value.
`static COSName` `SUBFILTER_ADBE_X509_RSA_SHA1` A signature subfilter value.
`static COSName` `SUBFILTER_ETSI_CADES_DETACHED` A signature subfilter value.

### Constructor Summary

Constructors
Constructor and Description
`PDSignature()` Default constructor.
`PDSignature(COSDictionary dict)` Constructor.

### Method Summary

All Methods Instance Methods Concrete Methods
`int[]` `getByteRange()` Read out the byterange from the file.
`String` `getContactInfo()` Returns the contact info provided by the signer to enable a recipient to contact the signer to verify the signature, e.g.
`byte[]` `getContents()` Returns the /Contents string as a byte array, i.e.
`byte[]` `getContents(byte[] pdfFile)` Will return the embedded signature between the byterange gap.
`byte[]` `getContents(InputStream pdfFile)` Will return the embedded signature between the byterange gap.
`COSDictionary` `getCOSObject()` Convert this standard java object to a COS dictionary.
`String` `getFilter()` Returns the filter.
`String` `getLocation()` Returns the CPU host name or physical location of the signing.
`String` `getName()` Returns the name of the person or authority signing the document.
`PDPropBuild` `getPropBuild()` PDF signature build dictionary.
`String` `getReason()` Returns the reason for the signing, such as (I agree...).
`Calendar` `getSignDate()` Returns the sign date.
`byte[]` `getSignedContent(byte[] pdfFile)` Return the signed content of the document.
`byte[]` `getSignedContent(InputStream pdfFile)` Return the signed content of the document.
`String` `getSubFilter()` Returns the subfilter.
`void` `setByteRange(int[] range)` Sets the byte range.
`void` `setContactInfo(String contactInfo)` Sets the contact info provided by the signer to enable a recipient to contact the signer to verify the signature, e.g.
`void` `setContents(byte[] bytes)` Sets the contents.
`void` `setFilter(COSName filter)` Set the filter.
`void` `setLocation(String location)` Sets the CPU host name or physical location of the signing.
`void` `setName(String name)` Sets the name of the person or authority signing the document.
`void` `setPropBuild(PDPropBuild propBuild)` PDF signature build dictionary.
`void` `setReason(String reason)` Sets the reason for the signing, such as (I agree...).
`void` `setSignDate(Calendar cal)` Set the sign date.
`void` `setSubFilter(COSName subfilter)` Set a subfilter that specify the signature that should be used.
`void` `setType(COSName type)` Set the dictionary type.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### FILTER_ADOBE_PPKLITE

    public static final COSName FILTER_ADOBE_PPKLITE

A signature filter value.

#### FILTER_ENTRUST_PPKEF

    public static final COSName FILTER_ENTRUST_PPKEF

A signature filter value.

#### FILTER_CICI_SIGNIT

    public static final COSName FILTER_CICI_SIGNIT

A signature filter value.

#### FILTER_VERISIGN_PPKVS

    public static final COSName FILTER_VERISIGN_PPKVS

A signature filter value.

#### SUBFILTER_ADBE_X509_RSA_SHA1

    public static final COSName SUBFILTER_ADBE_X509_RSA_SHA1

A signature subfilter value.

#### SUBFILTER_ADBE_PKCS7_DETACHED

    public static final COSName SUBFILTER_ADBE_PKCS7_DETACHED

A signature subfilter value.

#### SUBFILTER_ETSI_CADES_DETACHED

    public static final COSName SUBFILTER_ETSI_CADES_DETACHED

A signature subfilter value.

#### SUBFILTER_ADBE_PKCS7_SHA1

    public static final COSName SUBFILTER_ADBE_PKCS7_SHA1

A signature subfilter value.

### Constructor Detail

#### PDSignature

    public PDSignature()

Default constructor.

#### PDSignature

    public PDSignature(COSDictionary dict)

Constructor.

Parameters:
  `dict` - The signature dictionary.

### Method Detail

#### getCOSObject

    public COSDictionary getCOSObject()

Convert this standard java object to a COS dictionary.

Specified by:
  `getCOSObject` in interface `COSObjectable`
Returns:
  The COS dictionary that matches this Java object.

#### setType

    public void setType(COSName type)

Set the dictionary type.

Parameters:
  `type` - is the dictionary type.

#### setFilter

    public void setFilter(COSName filter)

Set the filter.

Parameters:
  `filter` - the filter to be used

#### setSubFilter

    public void setSubFilter(COSName subfilter)

Set a subfilter that specify the signature that should be used.

Parameters:
  `subfilter` - the subfilter that shall be used.

#### setName

    public void setName(String name)

Sets the name of the person or authority signing the document. According to the PDF specification, this value should be used only when it is not possible to extract the name from the signature.

Parameters:
  `name` - the name to be used

#### setLocation

    public void setLocation(String location)

Sets the CPU host name or physical location of the signing.

Parameters:
  `location` - the location to be used

#### setReason

    public void setReason(String reason)

Sets the reason for the signing, such as (I agree...).

Parameters:
  `reason` - the reason to be used

#### setContactInfo

    public void setContactInfo(String contactInfo)

Sets the contact info provided by the signer to enable a recipient to contact the signer to verify the signature, e.g. a phone number.

Parameters:
  `contactInfo` - the contact info to be used

#### setSignDate

    public void setSignDate(Calendar cal)

Set the sign date.

Parameters:
  `cal` - the date to be used as sign date

#### getFilter

    public String getFilter()

Returns the filter.

Returns:
  the filter

#### getSubFilter

    public String getSubFilter()

Returns the subfilter.

Returns:
  the subfilter

#### getName

    public String getName()

Returns the name of the person or authority signing the document. According to the PDF specification, this value should be used only when it is not possible to extract the name from the signature.

Returns:
  the name

#### getLocation

    public String getLocation()

Returns the CPU host name or physical location of the signing.

Returns:
  the location

#### getReason

    public String getReason()

Returns the reason for the signing, such as (I agree...).

Returns:
  the reason

#### getContactInfo

    public String getContactInfo()

Returns the contact info provided by the signer to enable a recipient to contact the signer to verify the signature, e.g. a phone number.

Returns:
  the contact info

#### getSignDate

    public Calendar getSignDate()

Returns the sign date.

Returns:
  the sign date

#### setByteRange

    public void setByteRange(int[] range)

Sets the byte range.

Parameters:
  `range` - the byte range to be used

#### getByteRange

    public int[] getByteRange()

Read out the byterange from the file.

Returns:
  an integer array with the byterange, or an empty array if there is none.

#### getContents

    public byte[] getContents()

Returns the /Contents string as a byte array, i.e. the embedded signature between the byterange gap.

Returns:
  a byte array containing the signature, or an empty array if there isn't any.

#### getContents

    public byte[] getContents(InputStream pdfFile)
                       throws IOException

Will return the embedded signature between the byterange gap.

Parameters:
  `pdfFile` - The signed pdf file as InputStream. It will be closed in this method.
Returns:
  a byte array containing the signature
Throws:
  `IOException` - if the pdfFile can't be read
  `IndexOutOfBoundsException` - if the byterange array is not long enough

#### getContents

    public byte[] getContents(byte[] pdfFile)
                       throws IOException

Will return the embedded signature between the byterange gap.

Parameters:
  `pdfFile` - The signed pdf file as byte array
Returns:
  a byte array containing the signature
Throws:
  `IOException` - if the pdfFile can't be read
  `IndexOutOfBoundsException` - if the byterange array is not long enough

#### setContents

    public void setContents(byte[] bytes)

Sets the contents.

Parameters:
  `bytes` - contents to be used

#### getSignedContent

    public byte[] getSignedContent(InputStream pdfFile)
                            throws IOException

Return the signed content of the document. This is not a PDF file, nor is it the PDF file before signing, it is the byte sequence made of the input minus the area where the signature bytes will be. See "The ByteRange and signature value" in the document Digital Signatures in a PDF.

Parameters:
  `pdfFile` - The signed pdf file as InputStream. It will be closed in this method.
Returns:
  a byte array containing only the signed part of the content
Throws:
  `IOException` - if the pdfFile can't be read

#### getSignedContent

    public byte[] getSignedContent(byte[] pdfFile)
                            throws IOException

Return the signed content of the document. This is not a PDF file, nor is it the PDF file before signing, it is the byte sequence made of the input minus the area where the signature bytes will be. See "The ByteRange and signature value" in the document Digital Signatures in a PDF.

Parameters:
  `pdfFile` - The signed pdf file as byte array
Returns:
  a byte array containing only the signed part of the content
Throws:
  `IOException` - if the pdfFile can't be read

#### getPropBuild

    public PDPropBuild getPropBuild()

PDF signature build dictionary. Provides information about the signature handler.

Returns:
  the pdf signature build dictionary.

#### setPropBuild

    public void setPropBuild(PDPropBuild propBuild)

PDF signature build dictionary. Provides information about the signature handler.

Parameters:
  `propBuild` - the prop build