Search content within the blog

Wednesday, June 3, 2009

Generate a HASH value using SQL Server 2005/2008

Do you want to pass a string and generate a HASH value from it using SQL Server? Here’s a very simple way of doing so using HashBytes. Let us see this with an example:

DECLARE @SomeValue nvarchar(50);
SELECT @SomeValue = 'SQLServerCurry';
SELECT HashBytes('SHA1', @SomeValue);
GO



generates an output

0x51FD96B1BD5CE0003370551D5498BA3C0E64BE4C

Using HashBytes, you can use algorithms like MD2, MD4, MD5, SHA or SHA1. The input string can be a varchar, nvarchar or varbinary and can be upto a maximum of 8000 bytes

No comments:

Post a Comment