error: java.security.ProviderException: Initialization failed
H� people,
I have taken an error while I am debugging my code? It may be caused from config file. My aim is to connect and enter p�n and then store my external cert�f�cate to smart card which has not support for java card. I am using ACR38 Smart card reader and compliant smart card....
Hata: java.security.ProviderException: Initialization failed
************************************************************************
# pkcs11.config
name = Safesign
library = C:\WINDOWS\system32\siecap11.dll
slot=1
attributes(*,CKO_PRIVATE_KEY,*) = {
CKA_SENSITIVE=true
}
attributes(*,CKO_PRIVATE_KEY,*) = {
CKA_TOKEN=true
}
attributes(*,CKO_PRIVATE_KEY,*) = {
CKA_SIGN = true
}
attributes(*,CKO_PRIVATE_KEY,*) = {
CKA_PRIVATE=true
}
attributes(*,CKO_PRIVATE_KEY,*) = {
CKA_MODIFIABLE=true
}
attributes(*,CKO_PRIVATE_KEY,*) = {
CKA_DERIVE=false
}
attributes(*,CKO_CERTIFICATE,*) = {
CKA_TRUSTED=true
}
attributes(*,CKO_CERTIFICATE,*) = {
CKA_TOKEN=true
}
attributes(*,CKO_CERTIFICATE,*) = {
CKA_MODIFIABLE=true
}
attributes(*,CKO_CERTIFICATE,*) = {
CKA_PRIVATE=true
}
****************************************************
My java program is that :
package test;
import java.io.*;
import java.util.*;
import java.lang.*;
import java.sql.*;
import java.text.*;
import java.math.*;
import java.security.*;
import java.security.cert.*;
import java.security.interfaces.*;
import javax.crypto.interfaces.*;
import javax.net.ssl.*;
import javax.crypto.*;
import javax.crypto.spec.DESKeySpec;
import java.security.KeyStore.*;
public class Main
{
private String configName = "C:\\Program Files\\Java\\jdk1.6.0_10\\jre\\lib\\security\\pkcs11.config";
private KeyStore ks=null;
public Main() {
}
public void loadID(String id)
{
try
{
ks.setEntry("id",new ID(id),new ProtectionParameterDummy());
}
catch(KeyStoreException e)
{
System.err.println("Failed to load ID to keystore");
}
}//loadID
public String retrieveID()
{
KeyStore.Entry entry=null;
try
{
entry=ks.getEntry("id",new ProtectionParameterDummy());
}
catch(NoSuchAlgorithmException e)
{
}
catch(UnrecoverableEntryException e)
{
System.err.println("Failed to retrieve ID to keystore");
}
catch(KeyStoreException e)
{
System.err.println("Failed to retrieve ID to keystore");
}
if (entry==null) {
return "noID";
}
else {
return ((ID)entry).getID();
}
}//loadID
public void login(String sPin) throws NoSuchProviderException, InvalidKeyException,
NoSuchPaddingException, InvalidAlgorithmParameterException
{
Provider p = new sun.security.pkcs11.SunPKCS11(configName);
Security.addProvider(p);
try
{
char pin[] = sPin.toCharArray();
ks = KeyStore.getInstance("pkcs11");
ks.load(null,pin);
}
catch(KeyStoreException e1)
{
System.out.println("error 1"+e1);
}
catch(NoSuchAlgorithmException e2)
{
System.out.println("Error 2"+e2);
}
catch(CertificateException e3)
{
System.out.println("error 3"+e3);
}
catch(IOException e4)
{
System.out.println("error 4"+e4);
}
}//loginToken
private class ID implements KeyStore.Entry
{
String id_="";
ID(String id)
{
id_=id;
}
public String getID()
{
return id_;
}
}//ID
private class ProtectionParameterDummy implements KeyStore.ProtectionParameter
{
}//ProtectionParameterDummy
public static void main (String args[]) throws Exception
{
try
{
Main tl = new Main();
tl.login("PIN");
tl.loadID("9876");
//System.out.println("id: "+tl.retrieveID());
}
catch(Exception e)
{
System.out.println("Hata: " + e.toString());
e.printStackTrace();
}
}//main
}
Error is taken from this command....
Provider p = new sun.security.pkcs11.SunPKCS11(configName);