AES_ENCRYPT (& #39; password & #39;, & #39; key & #39 ;)

Source: Internet
Author: User
In MySQL, the AES_ENCRYPT (password, key) function can encrypt the field values. the AES_DECRYPT (table field name, key) function decrypts the processing example. table structure: 650)this.srcwww.68idc.cnhelpuploadsallimg15111112064TK1-0.jpgtitletable.png altwKio

In MySQL, the AES_ENCRYPT ('password', 'key') function can encrypt the field values. the AES_DECRYPT (table field name, 'key') function decryption example. table structure: 650) this. width = 650; "src =" http://www.68idc.cn/help/uploads/allimg/151111/12064TK1-0.jpg "title =" table.png "alt =" wKio

MySQLAES_ENCRYPT ('password', 'key') functionEncryption of field values
AES_DECRYPT (table field name, 'key') functionDecryption


For example, table structure:

650) this. width = 650; "src =" http://www.68idc.cn/help/uploads/allimg/151111/12064TK1-0.jpg "title =" table.png "alt =" wKioL1YY1LvAA0sHAAEWJZP20qc946.jpg "/>


Insert a piece of data to encrypt the passwd password field.

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

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


, Successfully inserted. Let's take a look at the effect of database encryption:


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

We can see that it is encrypted and garbled.

The user needs to perform verification when logging on, and the program needs to be decrypted and passFunction AES_DECRYPT (table field name, 'key ')

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

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


As you can see, it has been decrypted.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.