use of org.jasypt.util.text.BasicTextEncryptor in project incubator-gobblin by apache.
the class ConfigUtilsTest method testConfigResolveEncrypted.
@Test
public void testConfigResolveEncrypted() throws IOException {
Map<String, String> vals = Maps.newHashMap();
vals.put("test.key1", "test_val1");
vals.put("test.key2", "test_val2");
State state = new State();
for (Map.Entry<String, String> entry : vals.entrySet()) {
state.setProp(entry.getKey(), entry.getValue());
}
String key = UUID.randomUUID().toString();
File keyFile = newKeyFile(key);
state.setProp(ConfigurationKeys.ENCRYPT_KEY_LOC, keyFile.getAbsolutePath());
Map<String, String> encryptedVals = Maps.newHashMap();
encryptedVals.put("my.nested.key1", "val1");
encryptedVals.put("my.nested.key2", "val2");
String encPrefix = "testenc";
for (Map.Entry<String, String> entry : encryptedVals.entrySet()) {
BasicTextEncryptor encryptor = new BasicTextEncryptor();
encryptor.setPassword(key);
String encrypted = "ENC(" + encryptor.encrypt(entry.getValue()) + ")";
state.setProp(encPrefix + "." + entry.getKey(), encrypted);
}
Config config = ConfigUtils.resolveEncrypted(ConfigUtils.propertiesToConfig(state.getProperties()), Optional.of(encPrefix));
Map<String, String> expected = ImmutableMap.<String, String>builder().putAll(vals).putAll(encryptedVals).build();
for (Map.Entry<String, String> entry : expected.entrySet()) {
String val = config.getString(entry.getKey());
Assert.assertEquals(val, entry.getValue());
}
keyFile.delete();
}
use of org.jasypt.util.text.BasicTextEncryptor in project omegat by omegat-org.
the class CredentialsManager method clearMasterPassword.
/**
* Clear the stored master password (if present) and the canary value.
* Afterwards, any encrypted values will be considered to be not set
* ({@link #isStored(String)} returns false; {@link #retrieve(String)}
* returns {@link Optional#empty()}).
*/
public void clearMasterPassword() {
clear(CREDENTIALS_MANAGER_CANARY);
clear(CREDENTIALS_MASTER_PASSWORD);
synchronized (this) {
textEncryptor = new BasicTextEncryptor();
}
}
use of org.jasypt.util.text.BasicTextEncryptor in project service-authorization by reportportal.
the class Encryptor method afterPropertiesSet.
@Override
public void afterPropertiesSet() throws Exception {
textEncryptor = new BasicTextEncryptor();
textEncryptor.setPassword(password);
}
Aggregations