Connecting Tech Pros Worldwide Forums | Help | Site Map

Encrypt and Decrypt a string variable

Member
 
Join Date: Sep 2007
Posts: 103
#1: Feb 6 '08
Hi all,

I have a string variable called userid and i want to encrypt the userid and store it into another variable using the stored procedure. Again i have to decrypt the encrypted value to the original string value using another stored procedure.

I am using sql server.

Please help me...

Thanks and regards,
Mathew

deepuv04's Avatar
Expert
 
Join Date: Nov 2007
Posts: 202
#2: Feb 7 '08

re: Encrypt and Decrypt a string variable


Quote:

Originally Posted by mathewgk80

Hi all,

I have a string variable called userid and i want to encrypt the userid and store it into another variable using the stored procedure. Again i have to decrypt the encrypted value to the original string value using another stored procedure.

I am using sql server.

Please help me...

Thanks and regards,
Mathew

In SQL Server 2000, you have to create your own user-defined functions to encrypt the data or use external DLLs to encrypt the data. In SQL Server 2005, these functions and methods are available by default.

SQL Server 2005 provides the following mechanism of encryption in order to encrypt the data.

* ENCRYPTION by passphrase
* ENCRYPTION by symmetric keys
* ENCRYPTION by Asymmetric keys
* ENCRYPTION by certificates

for simplycity you can use ENCRYPTION by passphrase method

“ENCRYPTION by passphrase” is basically encrypting the data using a password. The data can be decrypted using the same password.

eg:

select EncryptByPassPhrase('key', 'abc' )

result encrypted value: 0x01000000674FB952B3F9D575EB4B9E7A22BEC4800F6310C7 F96CA821

select convert(varchar(100),DecryptByPassPhrase('key'
, 0x01000000011FFAE33EA305F8DE68453A1CE3425C3F663849 D02F21CE))

result decrypted value : abc
Newbie
 
Join Date: Jun 2009
Posts: 2
#3: Jul 3 '09

re: Encrypt and Decrypt a string variable


Hi
If you are using SQL Server 2005, you can encrypt and decrypt any table values by creating certificate and master key. Refer to the article Encryption and Decryption in SQL Server 2005 using the url http://technotes.towardsjob.com/sql-...l-server-2005/

Hope it helps
Nitin
ck9663's Avatar
Expert
 
Join Date: Jun 2007
Posts: 1,925
#4: Jul 8 '09

re: Encrypt and Decrypt a string variable


Also, you might want to consider this....

Happy Coding!


--- CK
Reply