use of org.jasypt.util.text.BasicTextEncryptor in project ChatGameFontificator by GlitchCog.
the class FontificatorProperties method decryptProperty.
public void decryptProperty(String key) {
BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
textEncryptor.setPassword(ENC_PASSWORD);
final String encryptedValue = getProperty(key);
if (encryptedValue != null && !encryptedValue.isEmpty()) {
try {
final String decryptedValue = textEncryptor.decrypt(encryptedValue);
setProperty(key, decryptedValue);
} catch (Exception e) {
final String errorMessage = "Error decrypting value for " + key + " property";
logger.error(errorMessage, e);
ChatWindow.popup.handleProblem(errorMessage);
setProperty(key, "");
}
}
}
use of org.jasypt.util.text.BasicTextEncryptor in project incubator-gobblin by apache.
the class PasswordManagerTest method testMultipleMasterPasswords.
@Test
public void testMultipleMasterPasswords() throws IOException {
String password = UUID.randomUUID().toString();
String masterPassword = UUID.randomUUID().toString();
String masterPassword1 = UUID.randomUUID().toString();
String masterPassword2 = UUID.randomUUID().toString();
String masterPassword3 = UUID.randomUUID().toString();
File masterPasswordFile = File.createTempFile("masterPassword", null);
Files.write(masterPassword, masterPasswordFile, Charset.defaultCharset());
Files.write(masterPassword1, new File(masterPasswordFile.toString() + ".1"), Charset.defaultCharset());
Files.write(masterPassword2, new File(masterPasswordFile.toString() + ".2"), Charset.defaultCharset());
Files.write(masterPassword3, new File(masterPasswordFile.toString() + ".3"), Charset.defaultCharset());
State state = new State();
BasicTextEncryptor encryptor = new BasicTextEncryptor();
state.setProp(ConfigurationKeys.ENCRYPT_KEY_LOC, masterPasswordFile.toString());
state.setProp(ConfigurationKeys.NUMBER_OF_ENCRYPT_KEYS, 3);
PasswordManager passwordManager = PasswordManager.getInstance(state);
// Test current master password
encryptor.setPassword(masterPassword);
String encrypted = "ENC(" + encryptor.encrypt(password) + ")";
String decrypted = passwordManager.readPassword(encrypted);
Assert.assertEquals(decrypted, password);
// Test last master password using same passwordManager
encryptor = new BasicTextEncryptor();
encryptor.setPassword(masterPassword1);
encrypted = "ENC(" + encryptor.encrypt(password) + ")";
decrypted = passwordManager.readPassword(encrypted);
Assert.assertEquals(decrypted, password);
// Test second last master password using same passwordManager
encryptor = new BasicTextEncryptor();
encryptor.setPassword(masterPassword2);
encrypted = "ENC(" + encryptor.encrypt(password) + ")";
decrypted = passwordManager.readPassword(encrypted);
Assert.assertEquals(decrypted, password);
// Test third last master password using same passwordManager
// This one is not accepted because ConfigurationKeys.NUMBER_OF_ENCRYPT_KEYS = 3
encryptor = new BasicTextEncryptor();
encryptor.setPassword(masterPassword3);
encrypted = "ENC(" + encryptor.encrypt(password) + ")";
try {
passwordManager.readPassword(encrypted);
} catch (RuntimeException e) {
Assert.assertTrue(e.getMessage().startsWith("Failed to decrypt password"));
return;
}
Assert.fail("Password Manager decrypted too old password.");
}
use of org.jasypt.util.text.BasicTextEncryptor in project incubator-gobblin by apache.
the class DecryptConverterTest method setEncryptedPassphrase.
private void setEncryptedPassphrase(String plainPassphrase, State state) throws IOException {
String masterPassword = UUID.randomUUID().toString();
createMasterPwdFile(masterPassword);
state.setProp(ConfigurationKeys.ENCRYPT_KEY_LOC, this.masterPwdFile.toString());
state.setProp(ConfigurationKeys.ENCRYPT_USE_STRONG_ENCRYPTOR, false);
BasicTextEncryptor encryptor = new BasicTextEncryptor();
encryptor.setPassword(masterPassword);
String encrypted = encryptor.encrypt(plainPassphrase);
state.setProp("converter.decrypt.passphrase", "ENC(" + encrypted + ")");
}
use of org.jasypt.util.text.BasicTextEncryptor in project incubator-gobblin by apache.
the class CLIPasswordEncryptor method getEncryptor.
private static TextEncryptor getEncryptor(CommandLine cl, String masterPassword) {
if (cl.hasOption(STRONG_ENCRYPTOR_OPTION)) {
StrongTextEncryptor encryptor = new StrongTextEncryptor();
encryptor.setPassword(masterPassword);
return encryptor;
} else {
BasicTextEncryptor encryptor = new BasicTextEncryptor();
encryptor.setPassword(masterPassword);
return encryptor;
}
}
use of org.jasypt.util.text.BasicTextEncryptor in project tutorials by eugenp.
the class JasyptUnitTest method givenTextPrivateData_whenDecrypt_thenCompareToEncrypted.
@Test
public void givenTextPrivateData_whenDecrypt_thenCompareToEncrypted() {
// given
BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
String privateData = "secret-data";
textEncryptor.setPasswordCharArray("some-random-data".toCharArray());
// when
String myEncryptedText = textEncryptor.encrypt(privateData);
// myEncryptedText can be save in db
assertNotSame(privateData, myEncryptedText);
// then
String plainText = textEncryptor.decrypt(myEncryptedText);
assertEquals(plainText, privateData);
}
Aggregations