You need to use pgp_sym_encrypt for writing and pgp_sym_decrypt for reading. You did the opposite.
@ColumnTransformer( read = "pgp_sym_decrypt(" + " test, " + " current_setting('encrypt.key')" + ")", write = "pgp_sym_encrypt( " + " ?, " + " current_setting('encrypt.key')" + ") " ) @Column(columnDefinition = "bytea") private String test;
Since hard-coding an encryption key in a mapping is not a good idea, we will use PostgreSQL support for user settings instead.
So, the encrypt.key key is stored in the postgresql.conf configuration file:
encrypt.key = 'Wow! So much security.'
In fact, I liked your question so much that I even wrote an article about it . GitHub example and works like a charm.
source share