MySQL database encryption and decryption

Source: Internet
Author: User
Tags mysql database encryption

Summary:Data encryption and decryption are important in the area of security. For programmers, storing user passwords in a database with ciphertext is significant for intruders to steal users ' privacy. There are a variety of front-end encryption algorithms can be used for data encryption, decryption, below I recommend a simple database-level data encryption, decryption solution. Insert encrypted data into the table in the MySQL database, for example, it built the corresponding encryption function ...

Data encryption and decryption are important in the area of security. For programmers, storing user passwords in a database with ciphertext is significant for intruders to steal users ' privacy.

There are a variety of front-end encryption algorithms can be used for data encryption, decryption, below I recommend a simple database-level data encryption, decryption solution. In the case of MySQL database, it built the corresponding cryptographic function (Aes_encrypt ()) and decryption function (Aes_decrypt ()).

Inserting encrypted data into a table

    1. INSERT into userdata (Username,pasword,encryptedpassword)
    2. VALUES (' Smith ',' htims ', Aes_encrypt (' htims ',' key '))

The INSERT statement above has three fields, user name, password, and encrypted password. The Aes_encrypt () function requires a "key" to aid in encryption, and the decryption also requires it (keep in mind!). )。

The following is the data in the table:

Querying encrypted data from a table

    1. SELECT Username,pasword,aes_decrypt (Encryptedpassword,' key ')
    2. From UserData

The above query statement uses the Aes_decrypt () function. Here is the result of the operation:

In the above, we can see that the values of the "Pasword" and "Decryptedpassword" fields are the same, that is, you have decrypted the user's password. (Computer/compile)

MySQL database encryption and decryption

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.