Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server 2008 R2 HASHBYTES SHA2 returns null

I am trying to use HASHBYTES with SHA2_512 as the algo. However when I try to do it in SQL Server Management Studio all that I get is null.

SELECT HASHBYTES('SHA1','test') //works
SELECT HASHBYTES('SHA2','test') //returns null

What am I doing wrong?
Is there a way to view the return value from SELECT HASHBYTES('SHA2', 'test')?

thanks

like image 547
shikarishambu Avatar asked Apr 11 '12 22:04

shikarishambu


2 Answers

SQL Server supports SHA2 512 in SQL Server 2012+.

SQL Server 2008 R2 and below do NOT support SHA2_512. Here's HASHBYTES on MSDN.

like image 171
p.campbell Avatar answered Oct 05 '22 09:10

p.campbell


Here a small example with 128, 256 and 512 Bits

DECLARE @HashThis nvarchar(4000);
SELECT @HashThis = CONVERT(nvarchar(4000),'This is a sample string');
SELECT HASHBYTES('SHA1', @HashThis);
SELECT HASHBYTES('SHA2_256', @HashThis);
SELECT HASHBYTES('SHA2_512', @HashThis);
GO
like image 39
Carlos Avatar answered Oct 05 '22 09:10

Carlos