首页 > 代码库 > MySQL加密和解密案例

MySQL加密和解密案例

 1 define("ENCRYPT",2998a15c0cd853edad7);//密钥key
 2  
 3  
 4 被存储的数据库的字段设置成blob格式(二进制)
 5  //AES_ENCRYPT  加密
 6 insert into `ks_user`(user_name,user_pwd) values (kstest,AES_ENCRYPT(aa123456,2998a15c0cd853edad7));
 7  
 8  //AES_DECRYPT  解密
 9  select id,user_name, AES_DECRYPT(user_pwd,2998a15c0cd853edad7) AS user_pwd from `ks_user`;
10 +----+-----------+----------+
11 | id | user_name | user_pwd |
12 +----+-----------+----------+
13 |  8 | kstest    | aa123456 |
14 |  7 | hanks     | aa123456 |
15 +----+-----------+----------+
16 2 rows in set (0.16 sec)
17 
18 select * from `ks_user`;//原始数据存储的是二进制
19 +----+-----------+------------------+
20 | id | user_name | user_pwd         |
21 +----+-----------+------------------+
22 |  8 | kstest    | F?·У?5?f
23 |  7 | hanks     | F?·У?5?f
24 +----+-----------+------------------+
25 2 rows in set (0.15 sec)

 

MySQL加密和解密案例