MySQL database encryption and decryption

Source: Internet
Author: User
Tags mysql database encryption

Original http://codereflex.net/how-to-encrypt-decrypt-in-mysql/

Data encryption and decryption are very important in the security field. PairProgramIt is of great significance for intruders to plagiarize user privacy when using ciphertext to store user passwords in the database.

Multiple front-end encryptionAlgorithmIt can be used for data encryption and decryption. We 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 ()).

Insert encrypted data into the table

    1. Insert IntoUserdata (username, pasword, encryptedpassword)
    2. Values('Smith','Htids', Aes_encrypt ('Htids','Key'))

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

    1. SelectUsername, pasword, aes_decrypt (encryptedpassword,'Key')
    2. FromUserdata

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. (Zhang zhiping/compile)

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.