Tag: softhsm

SoftHSM2 java无法正常工作

我正在尝试在SoftHSM 2上进行POC,但有些我如何得到以下问题。 Exception in thread “main” java.security.ProviderException: Initialization failed at sun.security.pkcs11.SunPKCS11.(SunPKCS11.java:376) at sun.security.pkcs11.SunPKCS11.(SunPKCS11.java:103) at SoftHSM.main(SoftHSM.java:50) Caused by: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_SLOT_ID_INVALID at sun.security.pkcs11.wrapper.PKCS11.C_GetSlotInfo(Native Method) at sun.security.pkcs11.SunPKCS11.(SunPKCS11.java:365) … 2 more HSM配置文件: # SoftHSM v2 configuration file name= SoftHSM2 library = C:\SoftHSM2\lib\softhsm2-x64.dll slot=1 如果我评论slot = 1,那么我得到了 Exception in thread “main” java.security.ProviderException: Initialization failed at sun.security.pkcs11.SunPKCS11.(SunPKCS11.java:376) at sun.security.pkcs11.SunPKCS11.(SunPKCS11.java:103) at SoftHSM.main(SoftHSM.java:50) […]

连接到SoftHSM java

码: String pkcs11cfg = “pkcs11.cfg”; Provider p = new SunPKCS11(pkcs11cfg); Security.addProvider(p); KeyStore ks = KeyStore.getInstance(“PKCS11”, p); ks.load(null, pin); System.out.println(ks.size()); // prints 0 CFG: name = pkcs11Test library = /usr/local/lib/libsofthsm.so slot = 1 问题是我有一些密钥对,我用pkcs11-tool添加它们。 softhsm的版本是1.2.1 为什么KeyStore中没有任何别名? 如何解决这个问题?