import java.security.*; import java.util.*; import java.io.*; class TestSec { private static void listKeysInStore(KeyStore keyStore) throws Exception { Enumeration keyAliases = keyStore.aliases(); while (keyAliases.hasMoreElements()) { String keyAlias = keyAliases.nextElement(); if (keyStore.entryInstanceOf(keyAlias, KeyStore.PrivateKeyEntry.class)) System.out.println(keyAlias); } } public static void main(String[] args) throws Exception { // configure keystore name String keyStoreName = "JKS"; final String osName = System.getProperty("os.name"); if (osName.startsWith("Windows")) keyStoreName = "Windows-my"; else if (osName.startsWith("Mac OS X")) keyStoreName = "KeychainStore"; if (args.length > 0) keyStoreName = args[0]; // do the job KeyStore keyStore = KeyStore.getInstance(keyStoreName); keyStore.load(null, null); listKeysInStore(keyStore); } }