Detailed description of MySQL encryption and decryption instances

Source: Internet
Author: User

Detailed description of MySQL encryption and decryption instances

Detailed description of MySQL encryption and decryption instances

Data encryption and decryption are very important in the security field. For programmers, storing user passwords in a database in ciphertext is of great significance for intruders to plagiarize user privacy.
There are multiple front-end encryption algorithms for data encryption and decryption. I recommend a simple database-level data encryption and decryption solution. Take the MySQL database as an example. It has built-in encryption functions (AES_ENCRYPT () and decryption functions (AES_DECRYPT ()).

Pay attention to the field type when creating a table, as shown in:

Insert encrypted data into the table

The preceding insert statement has three fields: "User Name", "password", and "encrypted password ". The AES_ENCRYPT () function requires a "key" to assist in encryption. Similarly, decryption also requires it (please remember !).

The data in the table is as follows:

The preceding insert statement has three fields: "User Name", "password", and "encrypted password ". The AES_ENCRYPT () function requires a "key" to assist in encryption. Similarly, decryption also requires it (please remember !).

The data in the table is as follows:

Query encrypted data from a table

The preceding query statement uses the AES_DECRYPT () function. The running result is as follows:

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

Thank you for reading this article. I hope it will help you. Thank you for your support for this site!

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.