How to access certificates and private key from etoken using java

I work with a digital certificate and digital signature. We received the pfx file from the supplier. We convert this pfx file to a Java keystore and use it to create a digital signature using a java program. The seller now has etoken hardware. They give me the file in place of pf pfx. I transferred cer to jks key store and used it in my program ... My program told me that the private key is not there. I found that the secret key is missing. I talked with the seller about this, he said that the private key cannot be extracted from etoken .. you must directly contact etoken through the program to get the private key. Can someone tell me how I can access etoken programmatically. Is there a java api that is used for direct access to etoken. Help me....

0
java
source share
1 answer

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); } 
+1
source share

All Articles