/** * Returns the key associated with the given alias, using the given password to recover it. * * @param alias the alias name * @param password the password for recovering the key * @return the requested key, or null if the given alias does not exist or does not identify a * <i>key entry</i>. * @exception NoSuchAlgorithmException if the algorithm for recovering the key cannot be found * @exception UnrecoverableKeyException if the key cannot be recovered (e.g., the given password * is wrong). */ public Key engineGetKey(String alias, char[] password) throws NoSuchAlgorithmException, UnrecoverableKeyException { AbstractMap.SimpleEntry<String, Collection<KeyStore>> pair = getKeystoresForReading(alias); Key key = null; try { String entryAlias = pair.getKey(); for (KeyStore keystore : pair.getValue()) { key = keystore.getKey(entryAlias, password); if (key != null) { break; } } } catch (KeyStoreException e) { throw new IllegalStateException(e); } return key; }