I apologize for bringing this issue up again, but after hours of searching for guidance I can't find anything reliable. The last posting on this list and subject is:
[RE] Signing PDF with a PKCS11 smart card From: <[EMAIL PROTECTED]> - 2006-07-31 14:13 Based upon this and other postings, it seems that generating digital signature using "smart card" such a iKey 2032 should be as simple as the following code, probably coming from http://www.developer.com/security/article.php/3587361 - Java Applet for Signing with a Smart Card On the other hand, there are many other web postings suggesting that: a) one should be using KeyPair generation because the private key _never_ leaves the card/token b) the Sun's pkcs#11 interface is no good for iKey 2032 and you have to use low level interfaces c) . Since the following code (used both by : <[EMAIL PROTECTED]> - 2006-07-31 14:13 and the article above) fails for me, I am wondering: 1) Is this approach APPROPRIATE for the iKey 2032 USB device (can this work)? 2) Does anyone have Java code showing how to do this "right"? 3) Any pointers to some good documentation on this subject (Crypto books appear to handle this aspect in a very superficial way.) The following code fails with: java.security.InvalidKeyException: Private key must be instance of RSAPrivate(Crt)Key or have PKCS#8 encoding at java.security.Signature.initSign(Signature.java:485) import java.security.*; . SignerKeystorePKCS11 sk = new SignerKeystorePKCS11(config, passw); byte[] content = "This is the signed comntent".getBytes(); Signature signature = Signature.getInstance("SHA1withRSA", sk.getProvider()); ==> signature.initSign(sk.getPrivateKey()); signature.update(content); byte[] signatureBytes = signature.sign(); where: // Wrapper providing interface to the Rainbow Technologies iKey 2032 public class SignerKeystorePKCS11 { private Provider prov; private KeyStore ks; private String alias; private String pwd; private PrivateKey key; private Certificate[] chain; public SignerKeystorePKCS11(String config, String passw) throws Exception { this.pwd = passw; this.prov = new sun.security.pkcs11.SunPKCS11(config); Security.addProvider(prov); ks = KeyStore.getInstance("pkcs11"); ks.load(null, passw.toCharArray()); Enumeration<String> aliases = ks.aliases(); while (aliases.hasMoreElements()) { String a = (String) aliases.nextElement(); this.alias = a; this.key = (PrivateKey) ks.getKey(alias, pwd.toCharArray()); this.chain = ks.getCertificateChain(alias); X509Certificate cert =(X509Certificate) ks.getCertificate(a); PublicKey pub = cert.getPublicKey(); break; } } } public PrivateKey getPrivateKey() { return key; } public Certificate[] getChain() { return chain; } public Provider getProvider() { return prov; } } My configuration file (which may be the culprit of my exception) does not say a lot: name = rainbow_token library = c:\windows\system32\dkck232.dll attributes(*,CKO_PRIVATE_KEY,*) = { CKA_SIGN = true } attributes(*,CKO_PRIVATE_KEY,CKK_DH) = { CKA_SIGN = null } attributes(*,CKO_PRIVATE_KEY,CKK_RSA) = { CKA_DECRYPT = true } On a side note, I am constrained by a _need_ to use the SHA1 digest (can not used MD5 etc., even if that was kosher with PDF signature.). Martin Brunecky Software Architect RecordFusion <mailto:[EMAIL PROTECTED]> [EMAIL PROTECTED] AIM: mbrunecky tel: fax: <http://www.plaxo.com/click_to_call?src=jj_signature&To=303-865-8847+x+225&E [EMAIL PROTECTED]> 303-865-8847 x 225 303-865-8846 <https://www.plaxo.com/add_me?u=38655967504&v0=2505222&k0=891308811> Add me to your address book... <http://www.plaxo.com/signature> Want a signature like this?
<<image001.gif>>
------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/
_______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://itext.ugent.be/itext-in-action/
