public void testPropertiesFilePropertiesEncryption() throws Exception {
FileOutputStream fos = null;
FileInputStream fis = null;
try {
// Create a encryptor
StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
// Configure it
encryptor.setAlgorithm("PBEWithMD5AndDES");
encryptor.setPassword(PASSWORD_FOR_ENCRYPTION);
encryptor.setStringOutputType("base64");
encryptor.setKeyObtentionIterations(5);
// Create a properties file accessor that will use encryptor defined
// above to decrypt value. Note that this class do not encrypt value
// when we use setProperty() method, we must encrypt ourself the
// 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