if (!f.exists()) {
throw new IllegalStateException("The keystore file named '" + f + "' was not found.");
}
// Gets the keystore instance
KeyStore keyStore = null;
try {
keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
} catch (KeyStoreException e) {
throw new IllegalStateException("Error while getting a keystore ':" + e.getMessage());
}
// Load the keystore file
try {
keyStore.load(new BufferedInputStream(new FileInputStream(f)), keystorePass.toCharArray());
} catch (NoSuchAlgorithmException e) {
throw new IllegalStateException("Error while loading the keystore file '" + f + "'." + e.getMessage());
} catch (CertificateException e) {
throw new IllegalStateException("Error while loading the keystore file '" + f + "'." + e.getMessage());
} catch (FileNotFoundException e) {
throw new IllegalStateException("Error while loading the keystore file '" + f + "'." + e.getMessage());
} catch (IOException e) {
throw new IllegalStateException("Error while loading the keystore file '" + f + "'." + e.getMessage());
}
// Get certificate
Certificate cert;
try {
cert = keyStore.getCertificate(alias);
} catch (KeyStoreException e) {
throw new IllegalStateException("Error while getting the alias '" + alias + "' in the keystore file '" + keystoreFile + "':" + e.getMessage());
}
// set the public key