I would like to retrieve the same checksum value in C# instead of using SQL code?
The goal is to retrieve the same value in c# instead of using SQL code.
Is it possible to do it?
I can't find any good answer to my question.
I would like to retrieve the same checksum value in C# instead of using SQL code?
The goal is to retrieve the same value in c# instead of using SQL code.
Is it possible to do it?
I can't find any good answer to my question.
According to this old article:
The built-in CHECKUM function in SQL Server is built on a series of 4 bit left rotational xor operations
So you can try to implement this algorithm in C#.
However, that article states that this approach is not reliable from the point of collisions so probably you should not use this function at all.
I would recommend to use HASHBYTES with any reliable algorithm i.e. MD5 instead of this CHECKSUM. At the same time C# has built in functions for MD5:
byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes("admin@sqlfiddle.com"));
The Microsoft requirement is to use HASHBYTES rather than CHECKSUM function because HASHBYTES is more efficient than CHECKSUM.
I don't know what is the algorithm used by CHECKSUM, but HASHBYTES can use these hash algorithm (MD2 | MD4 | MD5 | SHA | SHA1 | SHA2_256 | SHA2_512). You can easily do the same thing in C# with the HashAlgorithm Class from System.Security.Cryptography.