Powered By Blogger

Saturday, 11 June 2011

encryption and decryption in mysql

In mysql we can encrypt and decrypt the data in many ways.
some of the examples are as follows:

1.) Encode and decode in mysql

mysql> select ENCODE('guessme', 'kiran');
+----------------------------+
| ENCODE('guessme', 'kiran') |
+----------------------------+
| ÕD]10÷8                      |
+----------------------------+
1 row in set (0.00 sec)

mysql> select decode('ÕD]10÷8','kiran');
+---------------------------+
| decode('ÕD]10÷8','kiran')   |
+---------------------------+
| guessme                   |
+---------------------------+
1 row in set (0.00 sec)

 #######################################################33

2.) AES_ENCRYPT and DES_ENCRYPT
mysql> create table app (user varchar(100),password varchar(100));
Query OK, 0 rows affected (0.09 sec)

mysql> insert into app values('user,',AES_ENCRYPT('text1','samplekey'));
Query OK, 1 row affected (0.01 sec)

mysql> select * from app;
+-------+-------------------------+
| user  | password                |
+-------+-------------------------+
| user, | QWâÃâºÂ¿1{3_pþyk        |
+-------+-------------------------+
1 row in set (0.00 sec)

mysql> select user, AES_DECRYPT(password,'samplekey') from app;

+-------+-----------------------------------+
| user  | AES_DECRYPT(password,'samplekey') |
+-------+-----------------------------------+
| user, | text1                             |
+-------+-----------------------------------+
1 row in set (0.00 sec)
 

No comments:

Post a Comment