You can write a SQL CLR function:
[Microsoft.SqlServer.Server.SqlFunction] public static SqlBinary BigHashBytes(SqlString algorithm, SqlString data) { var algo = HashAlgorithm.Create(algorithm.Value); var bytes = Encoding.UTF8.GetBytes(data.Value); return new SqlBinary(algo.ComputeHash(bytes)); }
And then it can be called in SQL as follows:
--these return the same value select HASHBYTES('md5', 'test stuff') select dbo.BigHashBytes('md5', 'test stuff')
BigHashBytes is only required if the length is more than 8k.
Paul tyng
source share