[Javamail-crypto-devel] PKCS11 and javamail-crypto
Status: Beta
Brought to you by:
akp
From: Victor S. <vi...@ca...> - 2011-05-27 11:14:12
|
Can I sign SMIME a message using a PKCS11 token? I have started from this example http://javamail-crypto.sourceforge.net/examples/SignMessage.java. I don't know how to replace this line smimeKeyMgr.loadPrivateKeystore(new FileInputStream(new File("./id.p12")), smimePw); With something that includes my private key from the token. I know the private key from PKCS11 can't be extracted. This is my code for accesing the token. KeyStore keystorePkcs11; keystorePkcs11 = KeyStore.getInstance("pkcs11"); keystorePkcs11.load(null, PASSWORD_PKCS11); Enumeration aliasesEnum = keystorePkcs11.aliases(); String alias = (String) aliasesEnum.nextElement(); X509Certificate cert = (X509Certificate) keystorePkcs11.getCertificate(alias); Key key = keystorePkcs11.getKey(alias, null); PrivateKey smimeKey = (PrivateKey) key; Thank you |