Search in sources :

Example 1 with BasicTextEncryptor

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, "");
        }
    }
}
Also used : BasicTextEncryptor(org.jasypt.util.text.BasicTextEncryptor)

Example 2 with BasicTextEncryptor

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.");
}
Also used : State(org.apache.gobblin.configuration.State) BasicTextEncryptor(org.jasypt.util.text.BasicTextEncryptor) File(java.io.File) Test(org.testng.annotations.Test)

Example 3 with BasicTextEncryptor

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 + ")");
}
Also used : BasicTextEncryptor(org.jasypt.util.text.BasicTextEncryptor)

Example 4 with BasicTextEncryptor

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;
    }
}
Also used : StrongTextEncryptor(org.jasypt.util.text.StrongTextEncryptor) BasicTextEncryptor(org.jasypt.util.text.BasicTextEncryptor)

Example 5 with BasicTextEncryptor

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);
}
Also used : BasicTextEncryptor(org.jasypt.util.text.BasicTextEncryptor) Test(org.junit.Test)

Aggregations

BasicTextEncryptor (org.jasypt.util.text.BasicTextEncryptor)13 File (java.io.File)4 State (org.apache.gobblin.configuration.State)4 Test (org.testng.annotations.Test)4 StrongTextEncryptor (org.jasypt.util.text.StrongTextEncryptor)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Closer (com.google.common.io.Closer)1 LineReader (com.google.common.io.LineReader)1 Config (com.typesafe.config.Config)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 ExecutionException (java.util.concurrent.ExecutionException)1 Path (org.apache.hadoop.fs.Path)1 TextEncryptor (org.jasypt.util.text.TextEncryptor)1 Test (org.junit.Test)1