Top Description Fields Constructors Methods
org.apache.pdfbox.pdmodel.interactive.digitalsignature

public Class PDSignature

extends Object
implements COSObjectable
Class Inheritance
All Implemented Interfaces
org.apache.pdfbox.pdmodel.common.COSObjectable
Imports
java.io.ByteArrayInputStream, .ByteArrayOutputStream, .IOException, .InputStream, java.nio.charset.StandardCharsets, java.util.Calendar, org.apache.pdfbox.cos.COSArray, .COSBase, .COSDictionary, .COSInteger, .COSName, .COSString, org.apache.pdfbox.pdmodel.common.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.
Authors
Ben Litchfield, Thomas Chojecki

Field Summary

Modifier and TypeField and Description
private final COSDictionary
public static final COSName
FILTER_ADOBE_PPKLITE

A signature filter value.

public static final COSName
FILTER_CICI_SIGNIT

A signature filter value.

public static final COSName
FILTER_ENTRUST_PPKEF

A signature filter value.

public static final COSName
FILTER_VERISIGN_PPKVS

A signature filter value.

public static final COSName
SUBFILTER_ADBE_PKCS7_DETACHED

A signature subfilter value.

public static final COSName
SUBFILTER_ADBE_PKCS7_SHA1

A signature subfilter value.

public static final COSName
SUBFILTER_ADBE_X509_RSA_SHA1

A signature subfilter value.

public static final COSName
SUBFILTER_ETSI_CADES_DETACHED

A signature subfilter value.

Constructor Summary

AccessConstructor and Description
public
PDSignature()

Default constructor.

public
PDSignature(COSDictionary
The signature dictionary.
dict
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
public int[]

Returns:

an integer array with the byterange, or an empty array if there is none.
getByteRange
()

Read out the byterange from the file.

public String

Returns:

the contact info
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.

public byte[]

Returns:

a byte array containing the signature, or an empty array if there isn't any.
getContents
()

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

public byte[]

Returns:

a byte array containing the signature
getContents
(InputStream
The signed pdf file as InputStream. It will be closed in this method.
pdfFile
)

Will return the embedded signature between the byterange gap.

public byte[]

Returns:

a byte array containing the signature
getContents
(byte[]
The signed pdf file as byte array
pdfFile
)

Will return the embedded signature between the byterange gap.

private byte[]
public COSDictionary

Returns:

The COS dictionary that matches this Java object.
getCOSObject
()

Implements org.apache.pdfbox.pdmodel.common.COSObjectable.getCOSObject.

Convert this standard java object to a COS dictionary.

public String

Returns:

the filter
getFilter
()

Returns the filter.

public String

Returns:

the location
getLocation
()

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

public String

Returns:

the name
getName
()

Returns the name of the person or authority signing the document.

public PDPropBuild

Returns:

the pdf signature build dictionary.
getPropBuild
()

PDF signature build dictionary.

public String

Returns:

the reason
getReason
()

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

public Calendar

Returns:

the sign date
getSignDate
()

Returns the sign date.

public byte[]

Returns:

a byte array containing only the signed part of the content
getSignedContent
(InputStream
The signed pdf file as InputStream. It will be closed in this method.
pdfFile
)

Return the signed content of the document.

public byte[]

Returns:

a byte array containing only the signed part of the content
getSignedContent
(byte[]
The signed pdf file as byte array
pdfFile
)

Return the signed content of the document.

public String

Returns:

the subfilter
getSubFilter
()

Returns the subfilter.

public void
setByteRange(int[]
the byte range to be used
range
)

Sets the byte range.

public void
setContactInfo(String
the contact info to be used
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.

public void
setContents(byte[]
contents to be used
bytes
)

Sets the contents.

public void
setFilter(COSName
the filter to be used
filter
)

Set the filter.

public void
setLocation(String
the location to be used
location
)

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

public void
setName(String
the name to be used
name
)

Sets the name of the person or authority signing the document.

public void
setPropBuild(PDPropBuild
the prop build
propBuild
)

PDF signature build dictionary.

public void
setReason(String
the reason to be used
reason
)

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

public void
setSignDate(Calendar
the date to be used as sign date
cal
)

Set the sign date.

public void
setSubFilter(COSName
the subfilter that shall be used.
subfilter
)

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

public void
setType(COSName
is the dictionary type.
type
)

Set the dictionary type.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

dictionaryback to summary
private final COSDictionary dictionary
FILTER_ADOBE_PPKLITEback to summary
public static final COSName FILTER_ADOBE_PPKLITE

A signature filter value.

FILTER_CICI_SIGNITback to summary
public static final COSName FILTER_CICI_SIGNIT

A signature filter value.

FILTER_ENTRUST_PPKEFback to summary
public static final COSName FILTER_ENTRUST_PPKEF

A signature filter value.

FILTER_VERISIGN_PPKVSback to summary
public static final COSName FILTER_VERISIGN_PPKVS

A signature filter value.

SUBFILTER_ADBE_PKCS7_DETACHEDback to summary
public static final COSName SUBFILTER_ADBE_PKCS7_DETACHED

A signature subfilter value.

SUBFILTER_ADBE_PKCS7_SHA1back to summary
public static final COSName SUBFILTER_ADBE_PKCS7_SHA1

A signature subfilter value.

SUBFILTER_ADBE_X509_RSA_SHA1back to summary
public static final COSName SUBFILTER_ADBE_X509_RSA_SHA1

A signature subfilter value.

SUBFILTER_ETSI_CADES_DETACHEDback to summary
public static final COSName SUBFILTER_ETSI_CADES_DETACHED

A signature subfilter value.

Constructor Detail

PDSignatureback to summary
public PDSignature()

Default constructor.

PDSignatureback to summary
public PDSignature(COSDictionary dict)

Constructor.

Parameters
dict:COSDictionary

The signature dictionary.

Method Detail

getByteRangeback to summary
public int[] getByteRange()

Read out the byterange from the file.

Returns:int[]

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

getContactInfoback to summary
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:String

the contact info

getContentsback to summary
public byte[] getContents()

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

Returns:byte[]

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

getContentsback to summary
public byte[] getContents(InputStream pdfFile) throws IOException

Will return the embedded signature between the byterange gap.

Parameters
pdfFile:InputStream

The signed pdf file as InputStream. It will be closed in this method.

Returns:byte[]

a byte array containing the signature

Exceptions
IOException:
if the pdfFile can't be read
IndexOutOfBoundsException:
if the byterange array is not long enough
getContentsback to summary
public byte[] getContents(byte[] pdfFile) throws IOException

Will return the embedded signature between the byterange gap.

Parameters
pdfFile:byte[]

The signed pdf file as byte array

Returns:byte[]

a byte array containing the signature

Exceptions
IOException:
if the pdfFile can't be read
IndexOutOfBoundsException:
if the byterange array is not long enough
getConvertedContentsback to summary
private byte[] getConvertedContents(InputStream is) throws IOException
getCOSObjectback to summary
public COSDictionary getCOSObject()

Implements org.apache.pdfbox.pdmodel.common.COSObjectable.getCOSObject.

Convert this standard java object to a COS dictionary.

Returns:COSDictionary

The COS dictionary that matches this Java object.

Annotations
@Override
getFilterback to summary
public String getFilter()

Returns the filter.

Returns:String

the filter

getLocationback to summary
public String getLocation()

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

Returns:String

the location

getNameback to summary
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:String

the name

getPropBuildback to summary
public PDPropBuild getPropBuild()

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

Returns:PDPropBuild

the pdf signature build dictionary.

getReasonback to summary
public String getReason()

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

Returns:String

the reason

getSignDateback to summary
public Calendar getSignDate()

Returns the sign date.

Returns:Calendar

the sign date

getSignedContentback to summary
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:InputStream

The signed pdf file as InputStream. It will be closed in this method.

Returns:byte[]

a byte array containing only the signed part of the content

Exceptions
IOException:
if the pdfFile can't be read
getSignedContentback to summary
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:byte[]

The signed pdf file as byte array

Returns:byte[]

a byte array containing only the signed part of the content

Exceptions
IOException:
if the pdfFile can't be read
getSubFilterback to summary
public String getSubFilter()

Returns the subfilter.

Returns:String

the subfilter

setByteRangeback to summary
public void setByteRange(int[] range)

Sets the byte range.

Parameters
range:int[]

the byte range to be used

setContactInfoback to summary
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:String

the contact info to be used

setContentsback to summary
public void setContents(byte[] bytes)

Sets the contents.

Parameters
bytes:byte[]

contents to be used

setFilterback to summary
public void setFilter(COSName filter)

Set the filter.

Parameters
filter:COSName

the filter to be used

setLocationback to summary
public void setLocation(String location)

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

Parameters
location:String

the location to be used

setNameback to summary
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:String

the name to be used

setPropBuildback to summary
public void setPropBuild(PDPropBuild propBuild)

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

Parameters
propBuild:PDPropBuild

the prop build

setReasonback to summary
public void setReason(String reason)

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

Parameters
reason:String

the reason to be used

setSignDateback to summary
public void setSignDate(Calendar cal)

Set the sign date.

Parameters
cal:Calendar

the date to be used as sign date

setSubFilterback to summary
public void setSubFilter(COSName subfilter)

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

Parameters
subfilter:COSName

the subfilter that shall be used.

setTypeback to summary
public void setType(COSName type)

Set the dictionary type.

Parameters
type:COSName

is the dictionary type.