23

Is there a built-in sha256 function in SQL Server? I can't find a sha256 T-SQL function source code either. Anyone who has an alternative?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
setzamora
  • 3,560
  • 6
  • 34
  • 48
  • See the answer here on SO: http://stackoverflow.com/questions/2954784/sha256-in-t-sql-stored-procedure – Simon Mourier Mar 17 '11 at 07:41
  • Refer https://stackoverflow.com/questions/33021992/i-want-to-get-hexadecimal-value-off-a-binary-value-removing-0x-from-it – LCJ Dec 26 '22 at 02:07

2 Answers2

45

SQL Server 2012 supports SHA2_256 and SHA2_512.

 SELECT HASHBYTES('SHA2_256','something')
Jacob Parker
  • 2,546
  • 18
  • 31
Soheil Bakhshi
  • 485
  • 4
  • 4
3

I think you are looking for HASHBYTES, but it supports only up to SHA-1 (160 bytes)

FYI Hashing is not encrypting. It is irreversible. Encryption is a process that is reversible to get the original data.

Reference for SHA2

SHA-2 is a set of cryptographic hash functions (SHA-224, SHA-256, SHA-384, SHA-512)


Here is a discussion about adding a salt to hashes

As for 256-byte hashing function - there isn't one built in.

RichardTheKiwi
  • 105,798
  • 26
  • 196
  • 262