Introducing DotNetFunda.com on mobile http://m.dotnetfunda.com ! Be with DotNetFunda.com on the go !
Go to DotNetFunda.com
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 6154 |  Welcome, Guest!   Register  Login
Home > Articles > Sql Server > Encrypt and Decrypt a Password using EncryptByPassPhrase and DecryptByPassPhrase

Encrypt and Decrypt a Password using EncryptByPassPhrase and DecryptByPassPhrase

4 vote(s)
Rating: 4.75 out of 5
Article posted by Syedshakeer on 5/16/2010 | Views: 9722 | Category: Sql Server | Level: Beginner red flag


This Article explains you how to Encrypt and Decrypt a text

Introduction

This Article explains you how to Encrypt and Decrypt a text.you can encrypt a password and can store a password as VarBinary in a column by using EncryptByPassPhrase functionEncrypted column can be decrypted by using DECRYPTBYPASSPHRASE function.

Explanation


EncryptByPassPhrase:


EncryptByPassPhrase uses the Triple DES algorithm to encrypt the text passed in.

 

Syntax: ENCRYPTBYPASSPHRASE('PASSPHRASE',‘text’)

 

In this statement, PASSPHRASE specifies the data string to be used to derive an encryption key,and 'text' data type shoulb be VarBinary.

 

Creating a 'login_details' table:-

 

create table login_details(uid integer,username varchar(10),password varbinary(100))

 

 

insert into login_details(uid,username,password) values(1,'smith',EncryptByPassPhrase('12',’XXX’))
insert into login_details(uid,username,password) values(2,'kennal',EncryptByPassPhrase('12','YYY'))
insert into login_details(uid,username,password) values(3,'staurt',EncryptByPassPhrase('12','ZZZ'))

 

 

 select * from login_details

 

 

DECRYPTBYPASSPHRASE:-

 

Encrypted column can be decrypted by using DECRYPTBYPASSPHRASE.

 

DECRYPTBYPASSPHRASE function takes two arguments one is 'PASSPHRASE'and text or column_name.

 

select uid,username, DECRYPTBYPASSPHRASE ('12',password) as Password from login_details

 

 In the above result the password still in VarBinary.So we have to Convert the VarBianry in Varchar by using Convert function as follows.

 select uid,username,convert(varchar(10), DECRYPTBYPASSPHRASE ('12',password)) from login_details



If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.

Page copy protected against web site content infringement by Copyscape
Found interesting? Add this to:



Please Sign In to vote for this post.

Experience:2 year(s)
Home page:http://www.dotnetfunda.com
Member since:Thursday, February 05, 2009
Level:Starter
Status: [Member]
Biography:Shakeer Hussain has completed his Master of Computer Applications degree from Deccan College of engg and technology of Osmania University.He is a MVM of www.dotnetspider.com.He has good experience in the areas of ASP.NET, C#.NET, VB.NET, SQL SERVER 2000/2005 and Windows Mobile. He has worked in Windows Mobile,Web Applicatin and ERP projects.
>> Write Response - Respond to this post and get points
Related Posts

This article describes you how to use triggers in SQL.

This articles shares the better programming standards and practices in database application programming using C# and Sql Server.

Hi all, Here how you can get all the stored procedure from a database. Hey not only the name but the stored procedures definitions also.

While loading data into a table I am disabling all the integrity constraints and after once I finished loading I am enabling all of them. Now the problem is some data which is not at all valid(Referred data not exists in parent table). How can I perform the integrity check on the loaded data and remove the unwanted same ?

This is part 38 of the series of article on SSIS. In this article we are going to see on how to use an Audit transformation control.

More ...
About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you found plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/21/2012 8:08:11 AM