I'm working on a C# project where we have a text value that is placed in a SQL Server database table in a nvarchar field. The value is hashed using the code below:
byte[] data = Encoding.ASCII.GetBytes("valuetohash");
byte[] bytes = new SHA512Managed().ComputeHash(data);
String result = Encoding.ASCII.GetString(bytes);
Now I need to duplicate creating that same value using T-SQL.
Can someone tell me how I can do that?
I tried HASHBYTES ( 'SHA2_512', 'valuetohash' )
but that lacks the ASCII encoding and produces a different value.
You need to convert binary data to a Base64 string and you may try using the CONVERT function:
SELECT CONVERT(varchar(max), HASHBYTES ('SHA2_512', 'valuetohash') ,2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With