sun.security.pkcs11.wrapper.PKCS11Exception:CKR_ATTRIBUTE_TYPE_INVALID

时间:2015-02-05 23:55:50

标签: java smartcard pkcs#11

我是SmartCard的新手,需要一些帮助。我尝试运行一个测试程序(见下文),但继续得到这个例外,sun.security.pkcs11.wrapper.PKCS11Exception: CKR_ATTRIBUTE_TYPE_INVALID

我的系统是Windows 7 64-bit,java版本是1.8.0_31

提前感谢您的帮助!

public static void main(String[] args) throws Exception { 
    final StringBuilder buff = new StringBuilder(); 
    buff.append("name=").append("SmartCard").append("\n"); 
    buff.append("library=").append("C:\\Progra~1\\ActivIdentity\\ActivClient\\acpkcs211.dll").append("\n");
    buff.append("showInfo=true").append("\n"); 
    buff.append("slotListIndex=0").append("\n"); 

    final SunPKCS11 provider = new sun.security.pkcs11.SunPKCS11(new ByteArrayInputStream(buff.toString().getBytes())); 
    Security.addProvider(provider);  

    KeyStore.ProtectionParameter pp = new KeyStore.PasswordProtection("######".toCharArray());  
    KeyStore.Builder builder = KeyStore.Builder.newInstance("PKCS11", provider, pp);
    KeyStore ks = builder.getKeyStore(); 
    ks.load(null, null); 
} 

输出:

Exception in thread "main" java.security.KeyStoreException: KeyStore instantiation failed
    at java.security.KeyStore$Builder$2.getKeyStore(Unknown Source)
    at myTests.P11Test.main(P11Test.java:38)
Caused by: java.io.IOException: load failed
    at sun.security.pkcs11.P11KeyStore.engineLoad(P11KeyStore.java:843)
    at java.security.KeyStore.load(Unknown Source)
    at java.security.KeyStore$Builder$2$1.run(Unknown Source)
    at java.security.KeyStore$Builder$2$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    ... 2 more
Caused by: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_ATTRIBUTE_TYPE_INVALID
    at sun.security.pkcs11.wrapper.PKCS11.C_FindObjectsInit(Native Method)
    at sun.security.pkcs11.P11KeyStore.findObjects(P11KeyStore.java:2658)
    at sun.security.pkcs11.P11KeyStore.mapLabels(P11KeyStore.java:2396)
    at sun.security.pkcs11.P11KeyStore.engineLoad(P11KeyStore.java:835)
    ... 6 more

1 个答案:

答案 0 :(得分:0)

我认为CKR_ATTRIBUTE_TYPE_INVALID错误表明传递的其中一个属性(可能是showInfo或slotListINdex)无效。尝试逐个删除它们,看看它是否修复了错误。