Home  >  Article  >  Database  >  Detailed explanation of encryption and decryption examples in MySQL

Detailed explanation of encryption and decryption examples in MySQL

黄舟
黄舟Original
2017-06-18 10:58:441473browse

This article mainly introduces the relevant information of MySQLEncryption and decryption examples, friends in need can refer to

MySQL encryption and decryption examples

Data encryption and decryption are very important in the security field. For programmers, storing user passwords in ciphertext in the database is of great significance to intruders who steal user privacy.
There are a variety of front-end encryption algorithms that can be used for data encryption and decryption. Below I recommend a simple database-level data encryption and decryption solution to you. Taking MySQL database as an example, it has built-in corresponding encryption function (AES_ENCRYPT()) and decryption function (AES_DECRYPT()).

When creating a table, pay attention to the field types. As shown in the figure below:

Insert encrypted data into the table

The above insert statement has three fields, "user name", " Password" and "Encrypted Password". The AES_ENCRYPT() function requires a "key" to assist in encryption, and it is also required for decryption (remember this!).

The following is a screenshot of the data in the table:

The insert statement above has three fields, "user name", "password" and " Encrypted password". The AES_ENCRYPT() function requires a "key" to assist in encryption, and it is also required for decryption (remember this!).

The following is a screenshot of the data in the table:

Query from the tableEncrypted data

The above query statement uses the AES_DECRYPT() function. The following is the running result:


In the above screenshot, we can see that the values ​​of the "pasword" and "decryptedpassword" fields are the same, that is, you have decrypted the user password.

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

Statement:
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