Class SignatureUtil
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Checks whether a name exists as a signature field or not.extractRevision
(String field) Extracts a revision from the document.Gets the field names that have blank signatures.int
getRevision
(String field) Get signed document revision number, which corresponds to the provided signature name.getSignature
(String name) GetPdfSignature
dictionary based on the provided name.getSignatureDictionary
(String name) Gets the signature dictionary, the one keyed by /V.Gets the field names that have signatures and are signed.int
Get the amount of signed document revisions.getTranslatedFieldName
(String name) Get field name, translated using XFA, if any present in the document.readSignatureData
(String signatureFieldName) Prepares anPdfPKCS7
instance for the given signature.readSignatureData
(String signatureFieldName, String securityProvider) Prepares anPdfPKCS7
instance for the given signature.boolean
Checks if the signature covers the entire document (except for signature's Contents) or just a part of it.
-
Constructor Details
-
SignatureUtil
Creates a SignatureUtil instance. Sets the acroForm field to the acroForm in the PdfDocument. iText will create a new AcroForm if the PdfDocument doesn't contain one.- Parameters:
-
document
- PdfDocument to be inspected
-
-
Method Details
-
readSignatureData
Prepares anPdfPKCS7
instance for the given signature. This method handles signature parsing and might throw an exception if signature is malformed.The returned
PdfPKCS7
can be used to fetch additional info about the signature and also to perform integrity check of data signed by the given signature field.In order to validate the signature it is required to check if it covers the entire file, otherwise one cannot be sure that signature in question indeed signs the data that constitutes current
PdfDocument
with all its contents. In order to check that given signature covers the currentPdfDocument
please usesignatureCoversWholeDocument(String)
method.- Parameters:
-
signatureFieldName
- the signature field name - Returns:
-
a
PdfPKCS7
instance which can be used to fetch additional info about the signature and also to perform integrity check of data signed by the given signature field.
-
readSignatureData
Prepares anPdfPKCS7
instance for the given signature. This method handles signature parsing and might throw an exception if signature is malformed.The returned
PdfPKCS7
can be used to fetch additional info about the signature and also to perform integrity check of data signed by the given signature field.Prepared
PdfPKCS7
instance calculates digest based on signature's /ByteRange entry. In order to check that /ByteRange is properly defined and given signature indeed covers the current PDF document revision please usesignatureCoversWholeDocument(String)
method.- Parameters:
-
signatureFieldName
- the signature field name -
securityProvider
- the security provider or null for the default provider - Returns:
-
a
PdfPKCS7
instance which can be used to fetch additional info about the signature and also to perform integrity check of data signed by the given signature field.
-
getSignature
GetPdfSignature
dictionary based on the provided name.- Parameters:
-
name
- signature name - Returns:
-
PdfSignature
instance corresponding to the provided name.null
otherwise
-
getSignatureDictionary
Gets the signature dictionary, the one keyed by /V.- Parameters:
-
name
- the field name - Returns:
-
the signature dictionary keyed by /V or
null
if the field is not a signature
-
getSignatureFormFieldDictionary
-
getSignatureNames
Gets the field names that have signatures and are signed.- Returns:
- List containing the field names that have signatures and are signed
-
getBlankSignatureNames
Gets the field names that have blank signatures.- Returns:
- List containing the field names that have blank signatures
-
getTotalRevisions
public int getTotalRevisions()Get the amount of signed document revisions.- Returns:
-
int
amount of signed document revisions
-
getRevision
Get signed document revision number, which corresponds to the provided signature name.- Parameters:
-
field
- signature name - Returns:
-
int
revision number
-
getTranslatedFieldName
Get field name, translated using XFA, if any present in the document.- Parameters:
-
name
- field name to be translated - Returns:
- translated field name if XFA is present, original name otherwise
-
extractRevision
Extracts a revision from the document.- Parameters:
-
field
- the signature field name - Returns:
- an InputStream covering the revision. Returns null if it's not a signature field
-
signatureCoversWholeDocument
Checks if the signature covers the entire document (except for signature's Contents) or just a part of it.If this method does not return
true
it means that signature in question does not cover the entire contents of currentPdfDocument
. Such signatures cannot be considered as verifying the PDF document, because content that is not covered by signature might have been modified since the signature creation.- Parameters:
-
name
- the signature field name - Returns:
- true if the signature covers the entire document, false if it doesn't
-
doesSignatureFieldExist
Checks whether a name exists as a signature field or not. It checks both signed fields and blank signatures.- Parameters:
-
name
- name of the field - Returns:
- boolean does the signature field exist
-