Search in sources :

Example 1 with StudioEncryption

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;
}
Also used : StudioEncryption(org.talend.utils.security.StudioEncryption) StudioEncryption(org.talend.utils.security.StudioEncryption)

Aggregations

StudioEncryption (org.talend.utils.security.StudioEncryption)1