Click here to Skip to main content
Click here to Skip to main content
Go to top

Encrypt and Decrypt password through SQL query

, 15 Apr 2013
Rate this:
Please Sign up or sign in to vote.
How to Encrypt And Decrypt a field without writing any frontent code .

Introduction

If we want to store our data in encrypted form, we use code for encryption and for decryption. But here we can store data in a database without writing lengthy code for it, we can do it in just two lines.

Using the code

First we have to create a database and a table.

create database Encrypt_Decrypt  ;//create database  
use Encrypt_Decrypt  ;// use database 
CREATE TABLE 'encrypt_decrypt'.'test' ('Username' VARCHAR(45) ,'Pswd' VARCHAR(45) ); //creating  table 
//Encryption start  
//Encrypt Pswd data at the time of inserting  
insert into 'encrypt_decrypt'.'test'(Username,Pswd) values('atul',AES_ENCRYPT('tiwari','.a.'));
//For decrypting Data 
SELECT Username,AES_DECRYPT(Pswd,'.a.') FROM test ;  // Here '.a.' is the Encrypt key

This code is tested in MySQL Server.

Points of Interest

While encrypting data we need a key, this should be unique and confidential because it will be further used in decrypting the data. If you forget the key then you can not decrypt your data.

For security purposes you can also put your key in the config file. 

For more help you can post your query.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

atul123321

United States United States
No Biography provided

Comments and Discussions

 
QuestionIt does not work for MS SQL PinmemberMember 1022937123-Jun-14 23:21 
QuestionPassword example? PinmemberBernhard Hiller16-Apr-13 0:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140905.1 | Last Updated 15 Apr 2013
Article Copyright 2013 by atul123321
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid