views:

37

answers:

2

Can i get installed certificates on my system through java

something like this Eg. Certificate[] certificate = someClass.getsystemCertificates();

Is there is some api available for this????

+2  A: 

You can use the keytool command to get the list of certificates in your cacerts file, which is the collection of approved certificates that Java comes with. The default password for this keystore is "changeit".

keytool -list -keystore $JAVA_HOME/jre/lib/security/cacerts -storepass changeit

Michael Angstadt
Getting such error i am using Windowskeytool error: java.lang.RuntimeException: Usage error, Files/Java/jre/lib/security is not a legal command
taher
There is a space in the path to your Java installation. Put quotes around the keystore path: `-keystore "$JAVA_HOME/jre/lib/security/cacerts"`
Michael Angstadt
hi I want this is in my program can u please elaborate code...
taher
Sorry, not sure how to do that.
Michael Angstadt
A: 

This depends on the system. Windows has centralized certificate storage, while other platforms don't (at least, no uniform one). So querying system certificates is platform-specific. And as it is, it would be wise to look for JNI to platform-specific API for doing what you need.

I guess there must be some class already available for Windows (most likely working via JNI), but I never saw one. I'd be interested in such solution too (for specific purposes where JNI can't be used).

Eugene Mayevski 'EldoS Corp