Listing the Aliases in a Key Store: A key store is a collection of keys and certificates. : KeyStore « Security « Java






Listing the Aliases in a Key Store: A key store is a collection of keys and certificates.

     

import java.io.FileInputStream;
import java.security.KeyStore;
import java.util.Enumeration;

public class Main {
  public static void main(String[] argv) throws Exception {
    FileInputStream is = new FileInputStream("yourfile"+".keystore");
    KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
    String password = "my-keystore-password";
    keystore.load(is, password.toCharArray());

    Enumeration e = keystore.aliases();
    for (; e.hasMoreElements();) {
      String alias = (String) e.nextElement();

      boolean b = keystore.isKeyEntry(alias);

      b = keystore.isCertificateEntry(alias);
    }
    is.close();
  }
}

   
    
    
    
    
  








Related examples in the same category

1.Exporting a Certificate to a File
2.Listing the Aliases in a Key Store using keytool:
3.Retrieving a Key Pair from a Key Store
4.Create a keystore with a self-signed certificate, using the keytool command
5.Import a key/certificate pair from a pkcs12 file into a regular JKS format keystore
6.This program signs a certificate, using the private key of another certificate in a keystore.
7.This class imports a key and a certificate into a keystore