Hibernate Encryption of Database Completely Transparent to Application

前端 未结 7 1017
春和景丽
春和景丽 2021-02-03 12:59

I\'m working on a Grails 1.0.4 project that has to be released in less than 2 weeks, and the customer just came up with a requirement that all data in the database should be enc

7条回答
  •  面向向阳花
    2021-02-03 13:38

    Generated ids, version, mapped foreign keys - basically everything maintained by Hibernate - are out unless you intend to declare custom CRUD for all of your classes and manually encrypt them in queries.

    For everything else you've got a couple of choices:

    1. @PostLoad and @PrePersist entity listeners will take care of all non-query operations.
    2. Implementing custom String / Long / Integer / etc... types to handle encryption will take care of both query and CRUD operations; however the mapping will become rather messy.
    3. You can write a thin wrapper around a JDBC driver (as well as Connection / Statement / PreparedStatement / ResultSet / etc...) to do the encryption for you.

    As far as queries go you'll have to handle encryption manually (unless you're going with #2 above) but you should be able to do so via a single entry point. I'm not sure how (or if) Grails deals with this, but using Spring, for example, it would be as easy as extending HibernateTemplate.

提交回复
热议问题