How to Encrypt Data in SQL

Posted by Krv under Sql Server category on | Points: 40 | Views : 1302
Sql provides support to encrypt data using below hash type

MD2 , MD4 , MD5 , SHA , SHA1 , SHA2_256 , SHA2_512

Syntax : HASHBYTES(<<Hash Type>>, <<Input Value>>

Eg :

Select HASHBYTES('MD4','dotnetfunda')

Comments or Responses

Posted by: T.Saravanan on: 11/15/2012 Level:Silver | Status: [Member] [MVP] | Points: 10
Hi Vasanth,

Nice info. Could you update your code with output of the query. Otherwise user cannot easily to understand your code and also explain how to read this encrypted value from database.
Posted by: Krv on: 11/20/2012 Level:Starter | Status: [Member] | Points: 10
Create table Test

OriginalValue varchar(max),
HashedValue varbinary(max)

Insert into Test values ('Dotnetfunda',HashBytes('MD5', 'Dotnetfunda'))

select *,SUBSTRING(master.dbo.fn_varbintohexstr(HashedValue), 3, 32) from Test

drop table Test

Hope this helps

Login to post response