Skip to content

Latest commit

 

History

History
16 lines (10 loc) · 1.02 KB

hash-values-in-sql-server.md

File metadata and controls

16 lines (10 loc) · 1.02 KB

Hash values in SQL Server

The HASHBYTES function allows you to choose an algorithm and hash a value. Its ouput is binary.

You can use SHA256 (and others). For added security, add a random, unique salt for each hash.

Store them in a binary column, or Base64 encode them and store them as VARCHAR.

Example, converting the hash:

CONVERT(VARCHAR(65), HASHBYTES('SHA2_256', CONCAT('SOME VALUE TO HASH', 'my_weak_salt')), 2)

Note: You may want more than 65. See this StackOverflow post for discussion.