Sunday , 25 June 2017
Home » SQL » How to hash a text in SQL Server

How to hash a text in SQL Server

How to hash a text in SQL Server

encryptionIn this article I am going to show you how to hash a text in SQL Server. First let me explain what is hashing or hash function?
“A hash function is any function that can be used to map digital data of arbitrary size to digital data of fixed size, with slight differences in input data producing very big differences in output data. The values returned by a hash function are called hash values, hash codes, hash sums, or simply hashes”. For more detailed information about hashing algorithms click on the following link Hash Function.

SQL Server has a built-in hashing function and its is called hashbytes(). This function requires 2 parameters in order to work. The first input parameter you need to give is the algorithm. SQL Server has 7 algorithms that can be used in hashing. The algorithms you can use are the followings:

  • MD2
  • MD4
  • MD5
  • SHA
  • SHA1
  • SHA2_256 (added in SQL Server 2012)
  • SHA2_512 (added in SQL Server 2012)

The second parameter is the text or string you want to hash. For better understanding see the code snippet below.

How to hash a text in sql server

Check Also

What is a Stored Procedure

What is a Stored Procedure What is a Stored Procedure? Stored procedures are a group …

Leave a Reply

Your email address will not be published. Required fields are marked *