Package com.itextpdf.signatures
Class PdfTwoPhaseSigner
java.lang.Object
com.itextpdf.signatures.PdfTwoPhaseSigner
Class that prepares document and adds the signature to it while performing signing operation in two steps (see
PadesTwoPhaseSigningHelper for more info).
Firstly, this class allows to prepare the document for signing and calculate the document digest to sign. Secondly, it adds an existing signature to a PDF where space was already reserved.
-
Constructor Summary
ConstructorsConstructorDescriptionPdfTwoPhaseSigner(PdfReader reader, OutputStream outputStream) Creates newPdfTwoPhaseSignerinstance. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddSignatureToPreparedDocument(PdfDocument document, String fieldName, OutputStream outs, byte[] signedContent) Deprecated.static voidaddSignatureToPreparedDocument(PdfDocument document, String fieldName, OutputStream outs, CMSContainer cmsContainer) Deprecated.addSignatureToPreparedDocument(PdfReader, String, OutputStream, CMSContainer)should be used instead.static voidaddSignatureToPreparedDocument(PdfReader reader, String fieldName, OutputStream outs, byte[] signedContent) Adds an existing signature to a PDF where space was already reserved.static voidaddSignatureToPreparedDocument(PdfReader reader, String fieldName, OutputStream outs, CMSContainer cmsContainer) Adds an existing signature to a PDF where space was already reserved.byte[]prepareDocumentForSignature(SignerProperties signerProperties, String digestAlgorithm, PdfName filter, PdfName subFilter, int estimatedSize, boolean includeDate) Prepares document for signing, calculates the document digest to sign and closes the document.setExternalDigest(IExternalDigest externalDigest) Use the external digest to inject specific digest implementationssetStampingProperties(StampingProperties stampingProperties) Set stamping properties to be used during main signing operation.
-
Constructor Details
-
PdfTwoPhaseSigner
Creates newPdfTwoPhaseSignerinstance.- Parameters:
-
reader-PdfReaderinstance to read the original PDF file -
outputStream-OutputStreamoutput stream to write the resulting PDF file into
-
-
Method Details
-
prepareDocumentForSignature
public byte[] prepareDocumentForSignature(SignerProperties signerProperties, String digestAlgorithm, PdfName filter, PdfName subFilter, int estimatedSize, boolean includeDate) throws IOException, GeneralSecurityException Prepares document for signing, calculates the document digest to sign and closes the document.- Parameters:
-
signerProperties-SignerPropertiesproperties to be used for main signing operation -
digestAlgorithm- the algorithm to generate the digest with -
filter- PdfName of the signature handler to use when validating this signature -
subFilter- PdfName that describes the encoding of the signature -
estimatedSize- the estimated size of the signature, this is the size of the space reserved for the Cryptographic Message Container -
includeDate- specifies if the signing date should be set to the signature dictionary - Returns:
- the message digest of the prepared document.
- Throws:
-
IOException- if some I/O problem occurs. -
GeneralSecurityException- if some problem during apply security algorithms occurs.
-
addSignatureToPreparedDocument
@Deprecated public static void addSignatureToPreparedDocument(PdfDocument document, String fieldName, OutputStream outs, CMSContainer cmsContainer) throws IOException, GeneralSecurityException Deprecated.addSignatureToPreparedDocument(PdfReader, String, OutputStream, CMSContainer)should be used instead.Adds an existing signature to a PDF where space was already reserved.- Parameters:
-
document- the original PDF -
fieldName- the field to sign. It must be the last field -
outs- the output PDF -
cmsContainer- the finalized CMS container - Throws:
-
IOException- if some I/O problem occurs. -
GeneralSecurityException- if some problem during apply security algorithms occurs.
-
addSignatureToPreparedDocument
public static void addSignatureToPreparedDocument(PdfReader reader, String fieldName, OutputStream outs, CMSContainer cmsContainer) throws IOException, GeneralSecurityException Adds an existing signature to a PDF where space was already reserved.- Parameters:
-
reader-PdfReaderthat reads the PDF file -
fieldName- the field to sign. It must be the last field -
outs- the output PDF -
cmsContainer- the finalized CMS container - Throws:
-
IOException- if some I/O problem occurs. -
GeneralSecurityException- if some problem during apply security algorithms occurs.
-
addSignatureToPreparedDocument
@Deprecated public static void addSignatureToPreparedDocument(PdfDocument document, String fieldName, OutputStream outs, byte[] signedContent) throws IOException, GeneralSecurityException Deprecated.addSignatureToPreparedDocument(PdfReader, String, OutputStream, byte[])should be used instead.Adds an existing signature to a PDF where space was already reserved.- Parameters:
-
document- the original PDF -
fieldName- the field to sign. It must be the last field -
outs- the output PDF -
signedContent- the bytes for the signed data - Throws:
-
IOException- if some I/O problem occurs. -
GeneralSecurityException- if some problem during apply security algorithms occurs.
-
addSignatureToPreparedDocument
public static void addSignatureToPreparedDocument(PdfReader reader, String fieldName, OutputStream outs, byte[] signedContent) throws IOException, GeneralSecurityException Adds an existing signature to a PDF where space was already reserved.- Parameters:
-
reader-PdfReaderthat reads the PDF file -
fieldName- the field to sign. It must be the last field -
outs- the output PDF -
signedContent- the bytes for the signed data - Throws:
-
IOException- if some I/O problem occurs. -
GeneralSecurityException- if some problem during apply security algorithms occurs.
-
setExternalDigest
Use the external digest to inject specific digest implementations- Parameters:
-
externalDigest- the IExternalDigest instance to use to generate Digests - Returns:
-
same instance of
PdfTwoPhaseSigner
-
setStampingProperties
Set stamping properties to be used during main signing operation.If none is set, stamping properties with append mode enabled will be used
- Parameters:
-
stampingProperties-StampingPropertiesinstance to be used during main signing operation - Returns:
-
same instance of
PdfTwoPhaseSigner
-
addSignatureToPreparedDocument(PdfReader, String, OutputStream, byte[])should be used instead.