OFM 10.3.6: Java code to view the contents of a Java Key Store (JKS)
package mindtelligent.custom.jks;import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.Certificate;
import java.util.Enumeration;
public class ViewJKSAlias {
private static InputStream is = null;
public static void main(String[] args) {
try {
File file =
new File("C:\\MindTelligent\\JavaKeyStore\\MindTelligentKeyStore.jks");
is = new FileInputStream(file);
KeyStore keystore =
KeyStore.getInstance(KeyStore.getDefaultType());
String password = "weblogic01";
keystore.load(is, password.toCharArray());
Enumeration enumeration = keystore.aliases();
while (enumeration.hasMoreElements()) {
String alias = (String)enumeration.nextElement();
System.out.println("alias name: " + alias);
Certificate certificate = keystore.getCertificate(alias);
System.out.println(certificate.toString());
}
} catch (java.security.cert.CertificateException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (KeyStoreException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (null != is)
try {
is.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}