FileOutputStream fos = null;
try {
// Load binary data from a image file
byte[] data = IOUtils.toByteArray(this.getClass().getResourceAsStream("/jasypt.png"));
// Declare a basic encryptor
BasicBinaryEncryptor be = new BasicBinaryEncryptor();
// Set password to use
be.setPassword(PASSWORD_FOR_ENCRYPTION);
// Encrypt data. By default the algorithm used is PBEWithMD5AndDES
byte[] encryptedData = be.encrypt(data);
// Valid "encrypted" data
byte[] decryptedData = be.decrypt(encryptedData);
Assert.assertArrayEquals(data, decryptedData);
// Create a image file with the decrypted data in order to validate
// that data are not corrupted
File f = File.createTempFile("JASYPT", ".png");
fos = new FileOutputStream(f);