use of org.talend.utils.security.StudioEncryption in project tbd-studio-se by Talend.
the class EncryptionUtil method getValue.
public static String getValue(String value, boolean encrypt) {
if (!value.startsWith("context.") && value != null && value.length() > 0) {
StudioEncryption se = StudioEncryption.getStudioEncryption(StudioEncryption.EncryptionKeyName.SYSTEM);
// Set default encrypt and decrypt methods
java.util.function.Function<String, String> encryptFunction = (src) -> se.encrypt(src);
java.util.function.Function<String, String> decryptFunction = (src) -> {
if (src != null && StudioEncryption.hasEncryptionSymbol(src)) {
return se.decrypt(src);
}
return src;
};
String newValue = null;
if (encrypt) {
newValue = encryptFunction.apply(value);
} else {
newValue = decryptFunction.apply(value);
}
if (newValue != null) {
// if enable to encrypt/decrypt will return the new value.
return newValue;
}
}
return value;
}
Aggregations