0

The situation is that I have an app which uses hibernate. I configured it to work with jasypt so that this app encrypt data into a database. Then, I have another app which read data from the database and it does not use hibernate. Both apps uses same database, and the second app needs to read and decrypt the data encrypted by the first app.

Right now I'm getting this exception despite I'm using the same jasypt pwd in both apps:

Exception in thread "main" org.jasypt.exceptions.EncryptionOperationNotPossibleException

I'm using BasicTextEncryptor to decrypt.

I would like to know if what I need is doable and if it is, how.

Note that jasypt encryption and decryption is working within the app that uses hibernate

McCoy
  • 780
  • 1
  • 10
  • 21
  • Do you use the same key to encrypt/decrypt the data going in/out of the database? There is no designated salt or anything stored somewhere on either sides? – vegaasen Jan 30 '17 at 07:23
  • yup, same key. No salt that I'm aware of – McCoy Jan 30 '17 at 14:18

1 Answers1

3

I had a similar error and I used BasicTextEncryptor as well.

Reason: BasicTextEncryptor uses StandardPBEStringEncryptor to make the magic. The last one uses salt and default salt is RandomSaltGenerator.

Solution: the clean way is to create your own encryptor with extending TextEncryptor interface (there are only a few methods). Take a look inside BasicTextEncryptor for the example.

Code example (to avoid the error):

StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
encryptor.setPassword(encryptionKey);
encryptor.setSaltGenerator(new StringFixedSaltGenerator(salt));
String encodedString = encryptor.encrypt(originalString);