One of my Postgresql entities has an encrypted column that I want decrypted when I read it with Spring Boot JPA. The encrypted entity fiels is decrypted with an hardcoded password :
@ColumnTransformer(
read = "pgp_sym_decrypt(secretField::bytea, 'secr3t'),
write = "pgp_sym_decrypt(?, 'secr3t')
)
private String secretField;
I want to externalize the 'secr3t' password, so it is not hardcoded anymore. But I cannot achieve this because :
- Spring Boot annotations can only contain constant strings (no
@Value("${encrypt.key}")possible to read it from application.properties) - I found the line
current_setting('encrypt.key')to write inread = "pgp_sym_decrypt(secretField::bytea, current_setting('encrypt.key')), but it tells meorg.postgresql.util.PSQLException: ERROR: unrecognized configuration parameter "encrypt.key"even if I declareencrypt.keyinapplication.properties. I read that this parameter should be written in the server-sidepostgresql.confconfiguration file, but it feels very weird not to have the password on the client side instead.
Is there a way to decrypt Postgresql columns with Spring Boot JPA without hardcoding the password ?
I really thought there would be a line in application.properties that I could write for this, since client-side key is possible, it is just... hardcoded by JPA constant values restriction.
Nothing that I found refers to Spring Boot JPA decryption on https://www.postgresql.org/docs/8.3/pgcrypto.html or on the spring boot documentation. Everybody just seem to make examples with a hard-coded key.
Related questions :
@ColumnTransformerbut use an@AttributeConverteror user-type which does the conversion.@AttributeConverterapproach is interesting, but I will need to manually decrypt the data, right ? In this case what is the way to know the initialisation verctor used by Postgres for an encryption ? Is there an example of manual Postgres decryption (whatever the language is) ?