Home >Database >Mysql Tutorial >Detailed explanation of MySQL password encryption and decryption

Detailed explanation of MySQL password encryption and decryption

藏色散人
藏色散人forward
2020-04-16 11:37:085014browse

MySQL password encryption and decryption detailed explanation

There are a variety of front-end encryption algorithms that can be used for data encryption and decryption. This is a simple database-level data encryption and decryption solution.

Take the MySQL database as an example. It has built-in corresponding encryption function (AES_ENCRYPT()) and decryption function (AES_DECRYPT()).

1. Create a table: Pay attention to the type of data when building a table

CREATE TABLE users( username VARCHAR(10), PASSWORD VARCHAR(10), testpswd VARBINARY(20) );

This table has three fields, 'username', 'password', 'encrypted password' '.

2. Insert data into the table

INSERT INTO users (username,PASSWORD,testpswd) VALUES ('sxyu','1233210',AES_ENCRYPT('1233210','key'));

Insert a record. The AES_ENCRYPT() function requires a "key" to assist encryption and decryption. It is also required. keep in mind.

3. Query the encrypted data (decryption) from the table:

SELECT username,PASSWORD,AES_DECRYPT(testpswd,'key') FROM users

It can be found from the query results that the decrypted password is the same as the original password.

Recommended: "mysql video tutorial"

The above is the detailed content of Detailed explanation of MySQL password encryption and decryption. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete