Encryption and Decryption of the data is very important when it comes to security,also for programmers when they want to develop a Login system it is also very important for them to store data into the database in the encrypted format because if any one have access to the database cannot see the actual password of the users.
There are many ways to encrypt and decrypt data some does at the front end level by their own encryption algorithm, but here I will show you a very easy way to encrypt and decrypt data at the database level.
So for this purpose MySQL gives you some built functions which you can use so here I will show you Encryption using AES_ENCRYPT() and for Decryption AES_DECRYPT() functions.
Inserting Encrypted data into the table:
INSERT INTO userdata (username,pasword,encryptedpassword)VALUES (‘smith’,'htims’,AES_ENCRYPT(‘htims’,'key’));
In the above insert statement three fields i.e (username,pasword,encryptedpassword) are inserted in the table called “userdata” inthe values you can notice that at the third field AES_ENCRYPT() function is used and two parameters are passed to that function first one ‘htims’ is the text to be encrypted and the second one ‘key’ is the encryption key you can specify any key, but remember this key because this key will be used when you decrypt the data. Here is a screen shot of the table showing how data looks like in the table after insertion:
Retrieving Decrypted data from the table:
SELECT username,pasword, AES_DECRYPT(encryptedpassword,’key’) FROM userdata ;
In the above select statement data is retrieved from the table userdata, Here you can notice a function AES_DECRYPT() which is used for decrypting the encrypted data and it requires two parameters one is the text or the field to be decrypted and the key which you specify at the time of encryption where you used AES_ENCRYPT() function. Following is the screen shot of the select statement.
In the above screen shot you can see that the pasword and the decryptedpassword field is the same as you have decrypted your encrypted password.
WELL after so much demand for video demonstration following is the video demo,have look and don’t forget to give feed back
CodeReflex is your foremost source of design practices, coding techniques and quality testing. Over here, you will get the solution of every known issue relevant to programming in mostly all of the top languages. Not only this but you can also download the code snippets by experts and freely incorporate into your project.