|
Jasypt Users Forum
Trying to encrypt database
Hi
I've implementing Jasypt 1.5 with Hibernate in a new project. I have a database with existing data and I need to encrypt it to start using Hibernate + Jasypt. This code retrieves the same encryptor used by Hibernate to encrypt/decrypt the data.
HibernatePBEEncryptorRegistry registry = HibernatePBEEncryptorRegistry.getInstance();
encryptor = registry.getPBEStringEncryptor("hibernateEncryptor");
connection = dataSource.getConnection ();
connection.setAutoCommit (false);
statement1 = connection.prepareStatement ("select * from table");
result = statement1.executeQuery ();
while (result.next ()) {
statement2 = connection.prepareStatement ("update table set column1 = ?, column2 = ? where id = ?");
statement2.setString (1, encryptor.encrypt (result.getString ("column1")));
statement2.setString (2, encryptor.encrypt (result.getString ("column2")));
statement2.setLong (3, result.getLong ("id"));
statement2.execute ();
statement2.close ();
}
connection.commit ();
I can encrypt and decrypt the database using this method and it works. I can use Hibernate to add new objects and retrieve them and it works. But if I encrypt with the above code and use Hibernate it will not work, it throws EncryptionOperationNotPossibleException. I don't know if Jasypt or Hibernate does something extra in the encryption/decryption process.
Regards,
Néstor Boscán
|