protected KeyStore loadKeyStore(InputStream inputStream, String keyStoreType) throws AmbariException {
    if (masterKeyService == null) {
      throw new AmbariException("Master Key Service is not set for this Credential store.");
    }

    KeyStore keyStore;
    try {
      keyStore = KeyStore.getInstance(keyStoreType);
    } catch (KeyStoreException e) {
      throw new AmbariException(String.format("No provider supports a key store implementation for the specified type: %s", keyStoreType), e);
    }

    try {
      keyStore.load(inputStream, masterKeyService.getMasterSecret());
    } catch (CertificateException e) {
      throw new AmbariException(String.format("One or more credentials from the key store could not be loaded: %s", e.getLocalizedMessage()), e);
    } catch (NoSuchAlgorithmException e) {
      throw new AmbariException(String.format("The algorithm used to check the integrity of the key store cannot be found: %s", e.getLocalizedMessage()), e);
    } catch (IOException e) {
      if (e.getCause() instanceof UnrecoverableKeyException) {
        throw new AmbariException(String.format("The password used to decrypt the key store is incorrect: %s", e.getLocalizedMessage()), e);
      } else {
        throw new AmbariException(String.format("Failed to read the key store: %s", e.getLocalizedMessage()), e);
      }
    }

    return keyStore;
  }
Loads a KeyStore from an InputStream
<p/>
Implementations are expected to call this to load the relevant KeyStore data from the
InputStream of some storage facility.

@param inputStream  the InputStream to read the data from
@param keyStoreType the type of key store data expected
@return a new KeyStore instance with the loaded data
@throws AmbariException if an error occurs while loading the key store data from the InputStream
ambari-server/src/main/java/org/apache/ambari/server/security/encryption/AbstractCredentialStore.java