Try this:
Put an attribute in your entity:
private byte[] encryptedBody;
Use this getter and setters:
@Column(columnDefinition= "LONGBLOB", name="encryptedBody")
@ColumnTransformer(
read="AES_DECRYPT(encryptedBody, 'yourkey')",
write="AES_ENCRYPT(?, 'yourkey')")
public byte[] getEncryptedBody() {
return encryptedBody;
}
public void setEncryptedBody(byte[] encryptedBody) {
this.encryptedBody = encryptedBody;
}
And then when you retrive the column use:
private final Charset UTF8_CHARSET = Charset.forName("UTF-8");
String decodeUTF8(byte[] bytes) {
return new String(bytes, UTF8_CHARSET);
}
String s = decodeUTF8(entity.getEncryptedBody());
BEWARE: AES_DECRYPT and AES_ENCRYPT belong to MySQL. If you have a different data base engine find similar functions.
Hope this helps.