Wednesday, 21 January 2015

How to use encrypt-decrypt data in MySQL database

You can directly store and retrieve data at the time of inserting it into database and select it from database.

Encrypt Data :

INSERT INTO a VALUES(1,aes_encrypt('anand','key123'));

aes_encrypt : Used to store data in encrypted format.
                      First argument is data to be stored in table.
              Second argument is key used to encrypt the data.

Table Data Should Be Like This.
SELECT * FROM a;
ID     Name
1        2 *ôé =äÓÉѤ˜Ff

Dcrypt Data :
SELECT ID, aes_decrypt(name,'key123') FROM a;
ID    Name
1      anand

aes_decrypt : Used to decrypt the column data.
              First argument is the column name which contain the encrypted data.
              Second argument is the key that is used at encryption time.


No comments:

Post a Comment