Search code examples
sql-serverencryptionencryption-symmetricencryption-asymmetric

Encrypting / Decrypting a passed value in SQL Server


I have the following scenario ...

A vendor sends a customer an email. At the bottom of the email is a link back to a web page that I am responsible for i.e. hosting. We need to pass the users email address through the link to the web page but we want it to be encrypted. We need to then be able to DECRYPT it on our end when we receive the request so that we can extract the email from it.

I would like for the vendor to be able to encrypt it via SQL Server (that's where the link is generated) and we would like to also decrypt it using SQL Server.

I have no, none, zero experience with encryption/decryption and need to devise a solution within the next 6 hours ... !!!

I see information on encrypting entire columns but I need to be able to encrypt/decrypt just a single string.

Any thoughts? Better approach?

Thanks, G


Solution

  • You can use EncryptByPassPhrase and DecryptByPassPhrase in SQL Server:

    select EncryptByPassPhrase('key', 'abc' );
    
    select convert(varchar(100),
       DecryptByPassPhrase('key', 0x0100000001E5B67F919CCC4B8EA10E97FC50764BF6B30EC4347C4E54));