The private key can be retrieved using PKCS11. To retrieve the private key from eToken in java, you need to pass the configuration file to the instance sun.security.pkcs11.SunPKCS11.
The configuration file must have the following properties:
name=<Name of Etoken> slot=<slot number for etoken> library=<path of the pckcs11 library(dll) for that etoken>
Below is an example code for retrieving a private key using eToken
PrivateKey privateKey = null; char password[] = "1234".toCharArray(); Provider userProvider = new sun.security.pkcs11.SunPKCS11("D:\\config.cfg"); ks = KeyStore.getInstance("PKCS11", userProvider); ks.load(null, password); Enumeration e = ks.aliases(); String alias=null; while (e.hasMoreElements()) { alias = (String) e.nextElement(); privateKey = (PrivateKey) ks.getKey(alias, password); }
Kunal surana
source share