Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem with safesign pkcs11 library

843811Sep 27 2009
Hello, everybody.

i am trying to write a sample application in order to access the certificates stored in safesign usb token.

I installed the pkcs11 driver provided by A.E.T ( aetpkss1.dll ) and then i write the following code :

/***********************************************/
try {

String configName = "c:/pkcs11.config";
sun.security.pkcs11.SunPKCS11 p = new sun.security.pkcs11.SunPKCS11(configName);
Security.addProvider(p);

char[] pin = {'1','2','3','4'};
KeyStore.Builder builder = KeyStore.Builder.newInstance("pkcs11",p ,new KeyStore.PasswordProtection(pin) );
KeyStore ks = builder.getKeyStore();

X509Certificate x509Cert = null;
Certificate c;

for (Enumeration list = ks.aliases(); list.hasMoreElements();) {
String alias = (String) list.nextElement();
System.out.println(alias);
c = ks.getCertificate(alias);

x509Cert = (X509Certificate) c;
System.out.println("--> Subject: " + x509Cert.getSubjectDN().getName());
System.out.println("--> Issuer: " + x509Cert.getIssuerDN().getName());

}
}

catch (Exception e) { e.printStackTrace(); }
/**************************************/

The configuration file contains the following two lines :

name = Safesign
library = c:\windows\system32\aetpkss1.dll


when i run this code I get the following exception :

java.security.KeyStoreException: KeyStore instantiation failed
at java.security.KeyStore$Builder$2.getKeyStore(KeyStore.java:1707)
at Pkidemo.main(Pkidemo.java:31)
Caused by: java.security.KeyStoreException: pkcs11 not found
at java.security.KeyStore.getInstance(KeyStore.java:676)
at java.security.KeyStore$Builder$2$1.run(KeyStore.java:1665)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.KeyStore$Builder$2.getKeyStore(KeyStore.java:1704)
... 1 more
Caused by: java.security.NoSuchAlgorithmException: no such algorithm: pkcs11 for
provider SunPKCS11-Safesign
at sun.security.jca.GetInstance.getService(GetInstance.java:83)
at sun.security.jca.GetInstance.getInstance(GetInstance.java:202)
at java.security.Security.getImpl(Security.java:688)
at java.security.KeyStore.getInstance(KeyStore.java:673)
... 4 more


Can anybody give me an explanation why is this happening ??
The token administrator utility shows that usb token works fine.


Thanks in advance.
forty.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 25 2009
Added on Sep 27 2009
0 comments
1,791 views