Connecting Tech Pros Worldwide Help | Site Map

Encrypt and Decrypt a string variable

  #1  
Old February 6th, 2008, 05:54 PM
Member
 
Join Date: Sep 2007
Posts: 103
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
  #2  
Old February 7th, 2008, 10:26 AM
deepuv04's Avatar
Expert
 
Join Date: Nov 2007
Posts: 202

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
  #3  
Old July 3rd, 2009, 07:06 AM
Newbie
 
Join Date: Jun 2009
Posts: 2

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
  #4  
Old July 8th, 2009, 05:15 PM
ck9663's Avatar
Expert
 
Join Date: Jun 2007
Posts: 1,914
Provided Answers: 1

re: Encrypt and Decrypt a string variable


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

Happy Coding!


--- CK
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
encrypting query string Onur Bozkurt answers 10 November 17th, 2005 07:15 PM
Encrypt a string to a string and vice versa Matthias S. answers 7 November 16th, 2005 01:42 PM
Encrypting a String Michael C answers 1 November 16th, 2005 12:21 PM
How to encrypt a Table Javier Gomez answers 10 November 13th, 2005 09:07 AM