spring-data-r2dbc icon indicating copy to clipboard operation
spring-data-r2dbc copied to clipboard

Model entity need to add custom Encryption on insert/update and decrypt on read

Open sandeep2244 opened this issue 2 years ago • 4 comments

Hello,

Can you guys define how to implement encryption, decryption on some of Model columns by custom annotation. Or any eventListener such as Hibernate in R2DBC can use ? We can find solution for JPA but not found for R2DBC.

sandeep2244 avatar Sep 29 '23 08:09 sandeep2244

There's no consistent way to post-process database values before writing them to the database or after returning these and before conversion into an entity.

mp911de avatar Sep 29 '23 08:09 mp911de

@mp911de does customConverter works with this requirement ? I mean just need to verify that, it won't make any issue to persist DB value, state right ?

sandeep2244 avatar Sep 29 '23 09:09 sandeep2244

CustomConversions uses type-based converters to e.g. apply conversion for temporal types or to serialize a custom type to bytes or JSON. We do not have sufficient hooks. While there's a BeforeSave callback, there's no way to post-process the loaded result when reading or when running a query.

mp911de avatar Sep 29 '23 09:09 mp911de

Sounds good @mp911de , I checked BeforeSaveCallback is of type based conversion at table level. May I know , does it work for annotation on Column based ?, requirement is to add encryption for some of the columns only.

sandeep2244 avatar Sep 29 '23 11:09 sandeep2244