Listing the Aliases in a Key Store

A key store is a collection of keys and certificates. Each key or certificate has a unique alias used to identify that key or certificate in the key store. This example lists all the aliases in a key store.
try { // Load the keystore in the user's home directory File file = new File(System.getProperty("user.home") + File.separatorChar + ".keystore"); FileInputStream is = new FileInputStream(file); KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType()); String password = "my-keystore-password"; keystore.load(is, password.toCharArray()); // List the aliases Enumeration enum = keystore.aliases(); for (; enum.hasMoreElements(); ) { String alias = (String)enum.nextElement(); // Does alias refer to a private key? boolean b = keystore.isKeyEntry(alias); // Does alias refer to a trusted certificate? b = keystore.isCertificateEntry(alias); } is.close(); } catch (java.security.cert.CertificateException e) { } catch (NoSuchAlgorithmException e) { } catch (FileNotFoundException e) { // Keystore does not exist } catch (KeyStoreException e) { } catch (IOException e) { }
The aliases can also be listed using keytool:
> keytool -list -storepass my-keystore-password

Comments

3 Sep 2010 - 12:52am by tudor watches (not verified)

It tag heure watches basically fills a nice gap Nike shoulder bag and, in many respects, it's Dior men like a win win win michele watches all around, he said. When gucci watches we presented in front of Nike for men insurance companies they liked it wallet gucci because it takes the heat alexander mcqueen shoes off of them a bit.

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.