PKCS11 problem - CKR_FUNCTION_FAILED
843811Jul 15 2008 — edited Jul 23 2008This is my code, I in the execution the provider was registered successfully, then I called this method.
{color:#0000ff}System.out.println("Start establish Keystore......");
char [] pin = {'1', '2', '3', '4','5','6','7','8'};
KeyStore smartCardKeyStore = KeyStore.getInstance("PKCS11",pkcs11Provider); *<- It always stucked at here.*{color}*
{color:#0000ff}smartCardKeyStore.load(null, pin);
System.out.println("Type= " + smartCardKeyStore.aliases());
System.out.println("Type= "+smartCardKeyStore.getType());
System.out.println("Provider= "+smartCardKeyStore.getProvider());
Enumeration aliasesEnum = smartCardKeyStore.aliases();
System.out.println("Has more entry= "+aliasesEnum.hasMoreElements());
while (aliasesEnum.hasMoreElements()) {
String alias = (String)aliasesEnum.nextElement();
System.out.println("Alias: " + alias);
X509Certificate cert =
(X509Certificate) smartCardKeyStore.getCertificate(alias);
System.out.println("Certificate: " + cert);
PrivateKey privateKey =
(PrivateKey) smartCardKeyStore.getKey(alias, null);
System.out.println("Private key: " + privateKey);
}
System.out.println("Established Keystore successfully......\n");{color}
after this execute, one exception was throwed....
{color:#ff6600}Start unregister PKCS11......
Unregistered successfully.....
{color:#ff6600}Start registering PKCS11.....
Registered successfully.....
Start establish Keystore......
java.io.IOException: load failed
at sun.security.pkcs11.P11KeyStore.engineLoad(P11KeyStore.java:755)
Error Message: IOException : load failed
at java.security.KeyStore.load(KeyStore.java:1150)
at ivestsmartcard.SmartCard.establishKeyStore(SmartCard.java:82)
at ivestsmartcard.Main.main(Main.java:18)
Caused by: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_FUNCTION_FAILED
at sun.security.pkcs11.wrapper.PKCS11.C_FindObjectsInit(Native Method)
at sun.security.pkcs11.P11KeyStore.mapLabels(P11KeyStore.java:2294)
at sun.security.pkcs11.P11KeyStore.engineLoad(P11KeyStore.java:739)
... 3 more{color}
Can anyone help me? have any solutions? I tried many times to find out the problem... I had refer so many examples, It look the same but the problem still prompted. please help me asap coz I m rushing....
TQ!
shawnnloo
Edited by: shawnnloo on Jul 15, 2008 7:35 PM
Edited by: shawnnloo on Jul 15, 2008 7:36 PM
Edited by: shawnnloo on Jul 15, 2008 7:38 PM
Edited by: shawnnloo on Jul 15, 2008 7:49 PM