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.