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!