Month: January 2014
At times you want a an easy and straightforward way to encrypt strings without the hassle of undocumented cryptographic libraries *cough* bouncy castle *cough*. This is where Jasypt comes in. It is a powerful encryption library that makes cryptography fun and easy! What makes Jasypt nice is that it can perform simple encryption using passwords very quickly. That is quickly in terms of development time.
PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor(); encryptor.setProviderName("BC"); encryptor.setAlgorithm("PBEWITHSHA256AND256BITAES-CBC-BC"); encryptor.setPoolSize(4); encryptor.setSaltGenerator(new RandomSaltGenerator()); encryptor.setKeyObtentionIterations(100000); encryptor.setPasswordCharArray("BadAssPassword12345!".toCharArray()); String crypted = encryptor.encrypt("Hello World!"); System.out.println(crypted); String plain = encryptor.decrypt(crypted); System.out.println(plain);