|
||||||||||||||||
TUTORIALS How to use Signer:
|
||||||||||||||||
| Class SignerModule |
| public Signature createSignature(String name, CustomPKCS7Signer signer) throws PdfException, IOException |
| Class Signature |
| public void sign(CustomPKCS7Signer signer) throws PdfException, IOException |
But let's have a closer look at the CustomPKCS7Signer class:

The class exposes five methods, called by jPDF Signer, as follows:
|
Step Name
|
Methods
|
Comments
|
|
Initialization
|
reset() | Resets the hardware signer. |
|
Calculation
|
update(byte) | Calculates the signature value. The bytes part of the signature calculation are passed one by one. |
|
Signature Generation
|
getSignatureDigest() getCertificateChain() getHashAlgoName() |
These methods are used to build a PKCS7 signature object compatible with Acrobat. |
Note that there are no methods to get/set the private key. That's because the private key is part of the hardware.
For more information regarding each method, please refer to the javadoc.
The process of generating a PDF signature is broken down into two main steps:
1. PREPARATION
This takes place when the code creates and/or signs the document.
jPDF Signer populates the PDF structure which will hold the PKCS7 signature. Among other things, the structure is filled with information about the signer certificate (name, location, contact #, etc.,...).
jPDF Signer also tries to figure out the size of the PKCS7 signature by running a dummy signature calculation.2. GENERATION
The generation is performed when the document is saved to the file system.
The final signature calculation is processed at this time. jPDF Signer calculates the file ranges element of the signature calculation (typically the whole file minus the range for the PKCS7 signature). It then processes all the bytes that are part of the signature calculation, next creates a valid PKCS7 that Acrobat can understand and, finally, writes it in the PDF file.Details of the calls to customPKCS7Signer:
PREPARATION
- In order to determine the size necessary to hold the signature in the PDF, jPDF Signer performs the following steps:
reset();
update(0);- A dummy PKCS7 signature is generated using the methods getHashAlgoName(), getSignatureDigest() and getCertificateChain().
- The signing certificate, getCertificateChain()[0], is used to fill the PDF signature structure with data (name, location, etc.,...)
GENERATION
- jPDF Signer calculates the correct signature byte ranges in order to skip the dummy signature allocated in the previous step.
- The final signature calculation takes place. The methods are called in this order:
reset()
// For each of the bytes part of the signature calculation:
update(b)- Finally, getHashAlgoName(), getSignatureDigest() and getCertificateChain() are called to create the final PKCS7 signature.
Samples
The jPDF distribution comes with two sample programs; one for the generation and the other for the validation.
For the purpose of the demo, we simulated the hardware device with a singleton class. It is recommended that you read the sample code to better understand how to implement a custom signer.
| © 2000-2007 Crionics Inc. |