use of org.jasypt.util.text.BasicTextEncryptor in project directory-fortress-core by apache.
the class EncryptUtil method init.
private void init() {
textEncryptor = new BasicTextEncryptor();
textEncryptor.setPassword(Config.getInstance().getProperty(CRYPTO_PROP, "adlfarerovcja;39 d"));
}
use of org.jasypt.util.text.BasicTextEncryptor in project ChatGameFontificator by GlitchCog.
the class FontificatorProperties method encryptProperty.
public void encryptProperty(String key) {
BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
textEncryptor.setPassword(ENC_PASSWORD);
final String decryptedValue = getProperty(key);
if (decryptedValue != null && !decryptedValue.isEmpty()) {
try {
final String encryptedValue = textEncryptor.encrypt(decryptedValue);
setProperty(key, encryptedValue);
} catch (Exception e) {
final String errorMessage = "Error encrypting 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 PasswordManager method getEncryptors.
private List<TextEncryptor> getEncryptors(CachedInstanceKey cacheKey) {
List<TextEncryptor> encryptors = new ArrayList<>();
int numOfEncryptionKeys = cacheKey.numOfEncryptionKeys;
String suffix = "";
int i = 1;
if (cacheKey.masterPasswordFile == null || numOfEncryptionKeys < 1) {
return encryptors;
}
Exception exception = null;
do {
Path currentMasterPasswordFile = new Path(cacheKey.masterPasswordFile + suffix);
try (Closer closer = Closer.create()) {
if (!fs.exists(currentMasterPasswordFile) || fs.getFileStatus(currentMasterPasswordFile).isDirectory()) {
continue;
}
InputStream in = closer.register(fs.open(currentMasterPasswordFile));
String masterPassword = new LineReader(new InputStreamReader(in, Charsets.UTF_8)).readLine();
TextEncryptor encryptor = useStrongEncryptor ? new StrongTextEncryptor() : new BasicTextEncryptor();
// setPassword() needs to be called via reflection since the TextEncryptor interface doesn't have this method.
encryptor.getClass().getMethod("setPassword", String.class).invoke(encryptor, masterPassword);
encryptors.add(encryptor);
suffix = "." + String.valueOf(i);
} catch (FileNotFoundException fnf) {
// It is ok for password files not being present
LOG.warn("Master password file " + currentMasterPasswordFile + " not found.");
} catch (IOException ioe) {
exception = ioe;
LOG.warn("Master password could not be read from file " + currentMasterPasswordFile);
} catch (Exception e) {
LOG.warn("Encryptor could not be instantiated.");
}
} while (i++ < numOfEncryptionKeys);
// Throw exception if could not read any existing password file
if (encryptors.size() < 1 && exception != null) {
throw new RuntimeException("Master Password could not be read from any master password file.", exception);
}
return encryptors;
}
use of org.jasypt.util.text.BasicTextEncryptor in project incubator-gobblin by apache.
the class PasswordManagerTest method testBasicEncryptionAndDecryption.
@Test
public void testBasicEncryptionAndDecryption() throws IOException {
String password = UUID.randomUUID().toString();
String masterPassword = UUID.randomUUID().toString();
File masterPwdFile = getMasterPwdFile(masterPassword);
State state = new State();
state.setProp(ConfigurationKeys.ENCRYPT_KEY_LOC, masterPwdFile.toString());
BasicTextEncryptor encryptor = new BasicTextEncryptor();
encryptor.setPassword(masterPassword);
String encrypted = encryptor.encrypt(password);
encrypted = "ENC(" + encrypted + ")";
String decrypted = PasswordManager.getInstance(state).readPassword(encrypted);
Assert.assertEquals(decrypted, password);
}
use of org.jasypt.util.text.BasicTextEncryptor in project incubator-gobblin by apache.
the class PasswordManagerTest method testMultipleMasterPasswordsWithoutPasswordFiles.
@Test
public void testMultipleMasterPasswordsWithoutPasswordFiles() throws IOException {
String password = UUID.randomUUID().toString();
String masterPassword = UUID.randomUUID().toString();
String masterPassword1 = UUID.randomUUID().toString();
File masterPasswordFile = File.createTempFile("masterPassword", null);
Files.write(masterPassword, masterPasswordFile, Charset.defaultCharset());
State state = new State();
BasicTextEncryptor encryptor = new BasicTextEncryptor();
state.setProp(ConfigurationKeys.ENCRYPT_KEY_LOC, masterPasswordFile.toString());
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
// This should throw FileNotFoundException as file for masterPassword1 is not created.
encryptor = new BasicTextEncryptor();
encryptor.setPassword(masterPassword1);
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 password without correct master password.");
}
Aggregations