I comment, I'm working with hibernate 4.3 in netbean with SQL connection and in my database I have the following table:
USUARIO(
ID_USUARIO VARCHAR(08) NOT NULL PRIMARY KEY
USU VARCHAR(12)
CLAVE VARBINARY(8000)
)
Before working with hibernate I was encrypting and decrypting my key with stored procedure using ENCRYPTBYPASSPHRASE and SQL DECRYPTBYPASSPHRASE, now that I work with hibernate I was using the same stored procedures and it works fine, but I was seeing that there is a way to do it directly with:
@Column(name = "CLAVE", nullable = false)
@ColumnTransformer(write = "ENCRYPTBYPASSPHRASE('frase',?)", read = "DECRYPTBYPASSPHRASE('frase',CLAVE)")
public byte[] getClave() {
return this.clave;
}
I also tried with (and still does not work)
CAST(DECRYPTBYPASSPHRASE('frase',CLAVE) as varchar(12))
But when doing my query and showing the key it shows me characters and not the key itself.
System.out.println("Pass 2: " + new String(usuario.getClave()));
According to what I read, what I do is fine, but does not work any idea of why?