Encryption of mysql data

Asked

Viewed 1,039 times

2

Can someone help me, I am using AES_ENCRYPT(string, string_key) (manual) to make 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'));

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 had been blank. See the imageinserir a descrição da imagem aqui

  • And what was the Warning that he gave?

  • (1 Row(s) affected, 1 Warning(s)) Execution Time : 00:00:00:140 Transfer Time : 00:00:00:000 Total Time : 00:00:00:00:140

  • @Fabrício, post the script creating your table too, please.

1 answer

3


AES_ENCRYPT() encrypts a string with a key and returns a binary string containing the encrypted output that must be stored in a field for binary data such as BLOB. To view a field BLOB you should cast to string, this can be done like this (in the case of some SQL editors this is done automatically, Mysql Workbench, for example, does not, already 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 cryptography you can use the function AES_DECRYPT(), for example:

SELECT CAST(AES_DECRYPT(codigoliberacao, 'chave') AS CHAR(50)) codigoliberacao_sem_criptografia 
FROM trava;
  • And how do I make the command Ert? This is my real ploblema INSERT INTO latch (code release) VALUES(aes_encrypt('22334455667788','qewretayhsgcvbdjfkrotit'));

  • The syntax is correct, but the data is being stored in what kind of data?

  • blz amidgo luide, I changed the type of data blob and Deu Certo. Thank you very much

  • You’re welcome. We’re here to help each other. :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.