An example of how to encrypt and decrypt entity fields with JPA converters and Spring Data JPA. See blog post.
Java 11
There is a User
entity which have different fields: id
, firstName
, lastName
, email
, birthDate
and creationDate
.
All fields except id
are encrypted in database using AES algorithm.
There is a simple UserRepository
which extends Spring Data JpaRepository
.
Encryption is enabled on fields using different JPA converters: StringCryptoConverter
, LocalDateCryptoConverter
and LocalDateTimeCryptoConverter
.
This is verified with UserRepositoryTest
integration test.
All converters are unit tested.
Encryption key is empty by default (see example.database.encryption.key
configuration key in application.yml
).
You have to provide an encryption key in configuration or specify it in options when running application.
./gradlew check