How to get al alias from hsm by SUNPKCS provider?

916 views Asked by At

I want to get my all key aliases from hsm, but i get this error message :

Exception in thread "main" java.io.IOException: load failed
    at sun.security.pkcs11.P11KeyStore.engineLoad(P11KeyStore.java:778)
    at java.security.KeyStore.load(KeyStore.java:1445)
    at eracom.provider.ProCrypt.main(ProCrypt.java:99)
    Caused by: sun.security.pkcs11.wrapper.PKCS11Exception: 
    CKR_OBJECT_HANDLE_INVALID
    at sun.security.pkcs11.wrapper.PKCS11.C_GetAttributeValue(Native Method)
    at sun.security.pkcs11.P11KeyStore.mapLabels(P11KeyStore.java:2415)
    at sun.security.pkcs11.P11KeyStore.engineLoad(P11KeyStore.java:770)

If i create just one secret key on hsm. there is no problem, i can get the alia from hsm, but if i have 2 or more, i get the error. How to solve it?

        KeyStore keyStore = KeyStore.getInstance("PKCS11", pkcs11);
        keyStore.load(null, slotPIN);

        SecretKey key = (SecretKey) keyStore.getKey("KEY2", slotPIN);
        System.out.println("key's attributes: " + key.toString());


        java.util.Enumeration<String> aliases = keyStore.aliases();
        String alias = null;
        while (aliases.hasMoreElements()) {
            alias = aliases.nextElement();
            System.out.println("key label name : " + alias);

        }
0

There are 0 answers