Hello, I'm using iText to sign pdf files, and I've got my private key on an
Aladdin eToken, which was formated with "secondary authentication mode with
RSA key", i.e. the token private keys are protected with another password.
The question is that when I sign a pdf file, the library calls twice
PdfPKCS7>>getEncodedPKCS7()... (on PdfSignatureAppearance>>preClose() and
PdfSignatureAppearance>>close() ) and this method calls the native C_Sign
function, wich needs the private key password.
The problem is that this behaviour is unwanted for me, because the final
user don't have to put the private key twice.
Do you know how can I avoid this??
This is my code (JDK 1.5):
String pkcs11config;
pkcs11config = "name = eToken\n";
pkcs11config += "library = c:\\WINDOWS\\system32\\eTpkcs11.dll\n";
pkcs11config += "disabledMechanisms = {\n";
pkcs11config += " CKM_SHA1_RSA_PKCS \n";
pkcs11config += "}";
InputStream confStream = new ByteArrayInputStream(pkcs11config
.getBytes());
SunPKCS11 sunpkcs11 = new SunPKCS11(confStream);
Security.addProvider(sunpkcs11);
KeyStore.Builder builder =
KeyStore.Builder.newInstance("PKCS11", sunpkcs11,
new KeyStore.CallbackHandlerProtection(new MyCallbackHandler()));
PrivateKey key = builder.getKeyStore().getKey("myAlias", null);
Certificate[] chain = builder.getKeyStore().getCertificateChain("myAlias");
X509Certificate userCert = (X509Certificate)
builder.getKeyStore().getCertificate("myAlias");
PdfReader reader_r1 = new PdfReader("pdf_original.pdf");
FileOutputStream fout_r1 = new FileOutputStream("pdfSigned_r1.pdf");
PdfStamper stp_r1 = PdfStamper.createSignature(reader_r1, fout_r1, '\0',
null, true);
PdfSignatureAppearance sap_r1 = stp_r1.getSignatureAppearance();
sap_r1.setCrypto(key, chain, null, PdfSignatureAppearance.WINCER_SIGNED);
sap_r1.setReason("a reason...");
sap_r1.setLocation("a location...");
Rectangle rect_r1 = new Rectangle(30, 30, 180, 80);
rect_r1.enableBorderSide(5);
rect_r1.setBorder(5);
sap_r1.setVisibleSignature(rect_r1, 1, null);
sap_r1.setImageScale(0.7F);
sap_r1.setImage(Image.getInstance("img/logo2.jpg"));
sap_r1.setLayer2Text("a layer 2 text here...");
stp_r1.close();
//--------------------------------------------------------------------
class MyCallbackHandler implements CallbackHandler {
public void handle(Callback[] callbacks) throws IOException,
UnsupportedCallbackException {
//do nothig, the driver login implementation is invoked
}
}
Thanks!!
------------------------------------------------------------------------------
EMC VNX: the world's simplest storage, starting under $10K
The only unified storage solution that offers unified management
Up to 160% more powerful than alternatives and 25% more efficient.
Guaranteed. http://p.sf.net/sfu/emc-vnx-dev2dev
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples:
http://itextpdf.com/themes/keywords.php