MySQL database encryption and decryption

Source: Internet
Author: User
Keywords Decryption Nbsp; crypt.
Tags data data encryption database encryption example functions key mysql mysql database

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)

Related Article

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.