Search code examples
javacryptographydigital-signaturekeystorepkcs#11

PKCS11Exception ckr_attribute_type_invalid


I am trying to create a keystore to get a private key with a smart card reader.

String config = "name = AKIS\nlibrary = C:/Windows/System32/akisp11.dll";
Security.addProvider(akisProvider);
KeyStore ks = KeyStore.getInstance("PKCS11", akisProvider);
ks.load(null, "000000".toCharArray());

But it gives me this exception:

java.io.IOException: load failed
    at sun.security.pkcs11.P11KeyStore.engineLoad(P11KeyStore.java:763)
    at java.security.KeyStore.load(KeyStore.java:1445)
    at deneme.AkisImzaImpl.dene(AkisImzaImpl.java:55)
    at deneme.Deneme.main(Deneme.java:83)
Caused by: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_ATTRIBUTE_TYPE_INVALID
    at sun.security.pkcs11.wrapper.PKCS11.C_GetAttributeValue(Native Method)
    at sun.security.pkcs11.wrapper.PKCS11$SynchronizedPKCS11.C_GetAttributeValue(PKCS11.java:1623)
    at sun.security.pkcs11.P11KeyStore.mapLabels(P11KeyStore.java:2277)
    at sun.security.pkcs11.P11KeyStore.engineLoad(P11KeyStore.java:755)
    ... 3 more

This code was working until yesterday. I could not figure out the problem. If you can help me I would really appreciate it.


Solution

  • I have worked it out. One of the 3 keys which does not have any ID was extra. I contacted the card company and we removed the extra key. Now it loads without a problem. Thanks for your help.