MySQL加密和解密案例
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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加密和解密案例的主要内容,如果未能解决你的问题,请参考以下文章