// property value an put
// encrypted property value using the syntax "ENC(encrypted_value)"
// in the property container. If the encrypted value is not surrounded
// by "ENC()" the EncryptableProperties object assume that the value isn't
// encrypted and read it as is...
Properties properties = new EncryptableProperties(encryptor);
// Fill properties container
// --Encrypt value
String encryptedValue = encryptor.encrypt(TEXT_TO_ENCRYPT);
// --Add value to the properties container
properties.setProperty("PASSWORD", "ENC(" + encryptedValue + ")");
// --Add a non encrypted propety
properties.setProperty("LOGIN", "MY_LOGIN");
// Save properties to a file
File f = File.createTempFile("JASYPT", ".properties");
fos = new FileOutputStream(f);
properties.store(fos, "Sample properties file");
System.out.printf("testPropertiesFilePropertiesEncryption : Properties file saved to '%s'\n", f.getAbsolutePath());
// Clear all properties and reload properties file
properties.clear();
Assert.assertNull(properties.getProperty("PASSWORD"));
Assert.assertNull(properties.getProperty("LOGIN"));
fis = new FileInputStream(f);
properties.load(fis);
// Valid properties stored value, the property decryption value is
// realized on the fly the EncryptableProperties object...
Assert.assertEquals(TEXT_TO_ENCRYPT, properties.getProperty("PASSWORD"));
Assert.assertEquals("MY_LOGIN", properties.getProperty("LOGIN"));
} finally {
IOUtils.closeQuietly(fos);
IOUtils.closeQuietly(fis);
}