thenatog commented on a change in pull request #4867: URL: https://github.com/apache/nifi/pull/4867#discussion_r585860727
########## File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/encrypt/StandardSensitiveValueEncoder.java ########## @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.encrypt; + +import org.apache.nifi.security.util.crypto.SecureHasher; +import org.apache.nifi.security.util.crypto.SecureHasherFactory; +import org.apache.nifi.util.NiFiProperties; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.crypto.Mac; +import javax.crypto.spec.SecretKeySpec; +import java.nio.charset.StandardCharsets; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.util.Base64; +import java.util.Objects; + +/** + * Encode a sensitive value using the NiFi sensitive properties key to derive the secret key used in the MAC operation. + */ +public class StandardSensitiveValueEncoder implements SensitiveValueEncoder { + + private static final Logger logger = LoggerFactory.getLogger(StandardSensitiveValueEncoder.class); + + private SecretKeySpec secretKeySpec; + private static final String HMAC_SHA256 = "HmacSHA256"; + + public StandardSensitiveValueEncoder(final NiFiProperties properties) { + this(properties.getProperty(NiFiProperties.SENSITIVE_PROPS_KEY), + SecureHasherFactory.getSecureHasher(properties.getProperty(NiFiProperties.SENSITIVE_PROPS_ALGORITHM))); + } + + // We use the sensitive properties key and a SecureHasher impl to derive a secret key for the getEncoded() method + public StandardSensitiveValueEncoder(final String sensitivePropertiesKey, final SecureHasher hasher) { Review comment: Yeah I think I originally was using this constructor and then as I went through the code I was grabbing both of these properties to pass them through to the constructor each time, and decided maybe it would be cleaner to pass the NiFiProperties through. Not sure what best practice is. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org