Data encryption and decryption are very important in the security field. For programmers, storing user passwords in ciphertext in a database is important to intruders who plagiarize users ' privacy.
There are a variety of front-end encryption algorithm can be used for data encryption, decryption, I recommend a simple database-level data encryption, decryption solution.
Take the MySQL database as an example, it built the corresponding cryptographic functions (Aes_encrypt ()) and decryption functions (Aes_decrypt ()).
Inserting encrypted data into a table
INSERT into UserData (Username,pasword,encryptedpassword) VALUES (' Smith ', ' Htims ', Aes_encrypt (' htims ', ' key ')
The INSERT statement above has three fields, username, password, and encrypted password. The Aes_encrypt () function requires a "key" to help with encryption, as well as decryption (remember!). )。
The following is a screenshot of the data in the table:
Querying encrypted data from a table
SELECT username,pasword,aes_decrypt (Encryptedpassword, ' key ') from UserData
The above query statement uses the Aes_decrypt () function. The following are the results of the operation:
In the screenshot above, we can see that the values for the "Pasword" and "Decryptedpassword" fields are the same, that is, you decrypted the user's password. (Zhang Zhiping/compiling)
(Responsible editor: The good of the Legacy)