mysql data encryption

2

Can anyone help me, I'm using AES_ENCRYPT (string, string_key) ( manual ) for do cryptographic with key.

Veja minha sintax. INSERT INTO trava (codigoliberacao) VALUES (AES_ENCRYPT('123456789', 'Chave'));

ie. insert into table (field) values (AES_ENCRYPT ('Value', 'Key'));

The mysql msg responds (1 row (s) affected, 1 warning (s)).

But in the normal query, the encryption does not appear, ie it is as if the field has been left blank. See the images

    
asked by anonymous 12.02.2015 / 13:59

1 answer

3

AES_ENCRYPT () encrypts a string with a key and returns a binary string containing the encrypted output that should be stored in a field for binary data such as BLOB . To view a BLOB field, you must do a cast to string, this can be done like this (in the case of some SQL editors this is done automatically, the MySQL Workbench, for example, does not already do SQLyog yes):

SELECT CAST(codigoliberacao AS CHAR(50)) AS codigoliberacao_string
FROM trava;

So you can see the data but, encrypted. But if you want to get it without encryption you can use the AES_DECRYPT () function, for example:

SELECT CAST(AES_DECRYPT(codigoliberacao, 'chave') AS CHAR(50)) codigoliberacao_sem_criptografia 
FROM trava;
    
12.02.2015 / 16:13