Home > Database > Mysql Tutorial > body text

MySQL中AES_ENCRYPT('密码','钥匙')

WBOY
Release: 2016-06-07 14:56:10
Original
1497 people have browsed it

MySQL中 AES_ENCRYPT('密码','钥匙')函数 可以对字段值做加密处理 AES_DECRYPT(表的字段名字,'钥匙')函数 解密 处理 例,表结构: 650) this.width=650;" src="http://www.68idc.cn/help/uploads/allimg/151111/12064TK1-0.jpg" title="table.png" alt="wKio

MySQL中AES_ENCRYPT('密码','钥匙')函数 可以对字段值做加密处理
       AES_DECRYPT(表的字段名字,'钥匙')函数 解密处理


例,表结构:

wKioL1YY1LvAA0sHAAEWJZP20qc946.jpg


现在插入一条数据,对passwd密码字段加密。

INSERT INTO credit_card(cid,NAME,email,passwd) 
VALUES(101,'hechunyang','hechunyang@163.com',AES_ENCRYPT('123456','hechunyang'));
Copy after login

650) this.width=650;" src="http://www.68idc.cn/help/uploads/allimg/151111/12064R140-1.jpg" title="1.png" alt="wKiom1YY1OLQaojCAAIHRLUEpNE953.jpg" />


如图所示,插入成功。下面看看数据库加密的效果:


650) this.width=650;" src="http://www.68idc.cn/help/uploads/allimg/151111/12064TD5-2.jpg" title="2.png" alt="wKioL1YY1RjQEnfCAAFuCivWWfo024.jpg" />

可以看到,已经加密,看见的是乱码。

用户登录的时候要进行验证,程序需要解密,通过函数AES_DECRYPT(表的字段名字,'钥匙')

SELECT cid,NAME,email,AES_DECRYPT(passwd,'hechunyang') as passwd FROM credit_card 
WHERE NAME='hechunyang';
Copy after login

wKioL1YY1VLB16baAAGoicSsUtw518.jpg


可以看到,已经解密。




Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template