Package com.itextpdf.signatures
Class PdfTwoPhaseSigner
- java.lang.Object
-
- com.itextpdf.signatures.PdfTwoPhaseSigner
-
public class PdfTwoPhaseSigner extends java.lang.Object
Class that prepares document and adds the signature to it while performing signing operation in two steps (seePadesTwoPhaseSigningHelper
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.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
closed
private IExternalDigest
externalDigest
private java.io.OutputStream
outputStream
private PdfReader
reader
private StampingProperties
stampingProperties
-
Constructor Summary
Constructors Constructor Description PdfTwoPhaseSigner(PdfReader reader, java.io.OutputStream outputStream)
Creates newPdfTwoPhaseSigner
instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
addSignatureToPreparedDocument(PdfDocument document, java.lang.String fieldName, java.io.OutputStream outs, byte[] signedContent)
Adds an existing signature to a PDF where space was already reserved.static void
addSignatureToPreparedDocument(PdfDocument document, java.lang.String fieldName, java.io.OutputStream outs, CMSContainer cmsContainer)
Adds an existing signature to a PDF where space was already reserved.(package private) PdfSigner
createPdfSigner(SignerProperties signerProperties)
byte[]
prepareDocumentForSignature(SignerProperties signerProperties, java.lang.String digestAlgorithm, PdfName filter, PdfName subFilter, int estimatedSize, boolean includeDate)
Prepares document for signing, calculates the document digest to sign and closes the document.private byte[]
prepareDocumentForSignature(SignerProperties signerProperties, java.security.MessageDigest messageDigest, PdfName filter, PdfName subFilter, int estimatedSize, boolean includeDate)
PdfTwoPhaseSigner
setExternalDigest(IExternalDigest externalDigest)
Use the external digest to inject specific digest implementationsPdfTwoPhaseSigner
setStampingProperties(StampingProperties stampingProperties)
Set stamping properties to be used during main signing operation.
-
-
-
Field Detail
-
reader
private final PdfReader reader
-
outputStream
private final java.io.OutputStream outputStream
-
externalDigest
private IExternalDigest externalDigest
-
stampingProperties
private StampingProperties stampingProperties
-
closed
private boolean closed
-
-
Constructor Detail
-
PdfTwoPhaseSigner
public PdfTwoPhaseSigner(PdfReader reader, java.io.OutputStream outputStream)
Creates newPdfTwoPhaseSigner
instance.- Parameters:
reader
-PdfReader
instance to read the original PDF fileoutputStream
-OutputStream
output stream to write the resulting PDF file into
-
-
Method Detail
-
prepareDocumentForSignature
public byte[] prepareDocumentForSignature(SignerProperties signerProperties, java.lang.String digestAlgorithm, PdfName filter, PdfName subFilter, int estimatedSize, boolean includeDate) throws java.io.IOException, java.security.GeneralSecurityException
Prepares document for signing, calculates the document digest to sign and closes the document.- Parameters:
signerProperties
-SignerProperties
properties to be used for main signing operationdigestAlgorithm
- the algorithm to generate the digest withfilter
- PdfName of the signature handler to use when validating this signaturesubFilter
- PdfName that describes the encoding of the signatureestimatedSize
- the estimated size of the signature, this is the size of the space reserved for the Cryptographic Message ContainerincludeDate
- specifies if the signing date should be set to the signature dictionary- Returns:
- the message digest of the prepared document.
- Throws:
java.io.IOException
- if some I/O problem occurs.java.security.GeneralSecurityException
- if some problem during apply security algorithms occurs.
-
addSignatureToPreparedDocument
public static void addSignatureToPreparedDocument(PdfDocument document, java.lang.String fieldName, java.io.OutputStream outs, CMSContainer cmsContainer) throws java.io.IOException, java.security.GeneralSecurityException
Adds an existing signature to a PDF where space was already reserved.- Parameters:
document
- the original PDFfieldName
- the field to sign. It must be the last fieldouts
- the output PDFcmsContainer
- the finalized CMS container- Throws:
java.io.IOException
- if some I/O problem occurs.java.security.GeneralSecurityException
- if some problem during apply security algorithms occurs.
-
addSignatureToPreparedDocument
public static void addSignatureToPreparedDocument(PdfDocument document, java.lang.String fieldName, java.io.OutputStream outs, byte[] signedContent) throws java.io.IOException, java.security.GeneralSecurityException
Adds an existing signature to a PDF where space was already reserved.- Parameters:
document
- the original PDFfieldName
- the field to sign. It must be the last fieldouts
- the output PDFsignedContent
- the bytes for the signed data- Throws:
java.io.IOException
- if some I/O problem occurs.java.security.GeneralSecurityException
- if some problem during apply security algorithms occurs.
-
setExternalDigest
public PdfTwoPhaseSigner setExternalDigest(IExternalDigest externalDigest)
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
public PdfTwoPhaseSigner setStampingProperties(StampingProperties stampingProperties)
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
-StampingProperties
instance to be used during main signing operation- Returns:
- same instance of
PdfTwoPhaseSigner
-
createPdfSigner
PdfSigner createPdfSigner(SignerProperties signerProperties) throws java.io.IOException
- Throws:
java.io.IOException
-
prepareDocumentForSignature
private byte[] prepareDocumentForSignature(SignerProperties signerProperties, java.security.MessageDigest messageDigest, PdfName filter, PdfName subFilter, int estimatedSize, boolean includeDate) throws java.io.IOException
- Throws:
java.io.IOException
-
-