protected void addCredential(KeyStore keyStore, String alias, Credential credential) throws AmbariException {
    if (keyStore != null) {
      try {
        Key key;
        char[] value = (credential == null) ? null : credential.toValue();

        if ((value == null) || (value.length == 0)) {
          key = null;
        } else {
          key = new SecretKeySpec(toBytes(value), "AES");
        }

        keyStore.setKeyEntry(alias, key, masterKeyService.getMasterSecret(), null);
      } catch (KeyStoreException e) {
        throw new AmbariException("The key store has not been initialized", e);
      }
    }
  }
Adds a new credential to the supplied KeyStore
<p/>
The supplied key will be converted into UTF-8 bytes before being stored.

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