protected void encrypt(Map<String, String> configProperties, Cluster cluster, String configType, Function<String,String> encryption) {
    final Set<String> passwordProperties = getPasswordProperties(cluster, configType);
    if (CollectionUtils.isNotEmpty(passwordProperties)) {
      for (Map.Entry<String, String> property : configProperties.entrySet()) {
        if (shouldEncrypt(property, passwordProperties)) {
          configProperties.put(property.getKey(), encryption.apply(property.getValue()));
        }
      }
    }
  }
A common base class for various encryptor implementations
ambari-server/src/main/java/org/apache/ambari/server/security/encryption/PropertiesEncryptor.java