protected Credential getCredential(KeyStore keyStore, String alias) throws AmbariException {
    char[] value = null;

    if (keyStore != null) {
      try {
        Key key = keyStore.getKey(alias, masterKeyService.getMasterSecret());
        if (key != null) {
          value = toChars(key.getEncoded());
        }
      } catch (UnrecoverableKeyException e) {
        throw new AmbariException("The key cannot be recovered (e.g., the given password is wrong)", e);
      } catch (KeyStoreException e) {
        throw new AmbariException("The key store has not been initialized", e);
      } catch (NoSuchAlgorithmException e) {
        throw new AmbariException(" if the algorithm for recovering the key cannot be found", e);
      }
    }

    return CredentialFactory.createCredential(value);
  }
Retrieves the specified credential from a KeyStore

@param keyStore the KeyStore
@param alias    a string declaring the alias (or name) of the credential
@return an array of chars containing the credential
@throws AmbariException if an error occurs while retrieving the new credential
ambari-server/src/main/java/org/apache/ambari/server/security/encryption/AbstractCredentialStore.java