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)
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.