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
- INSERT into userdata (Username,pasword,encryptedpassword)
- 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
- SELECT Username,pasword,aes_decrypt (Encryptedpassword,' key ')
- 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