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
- Insert IntoUserdata (username, pasword, encryptedpassword)
- 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
- SelectUsername, pasword, aes_decrypt (encryptedpassword,'Key')
- 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)