HashBytes

HashBytes

Sometimes people have confusion about use of hash or encryption
There are 2 basic difference between them on which you can decide how to use it



Hash is one way once you do it cant recover string from it
Encryption is two way , you can recover string from encrypted data

Hash will always give you same result for the input
Encryption doesn't give such guarantee for this. For same input multiple times we can have different encrypted output.
So we cant encrypted result for any comparison or join

From BOL HashBytes supports five algorithms

HashBytes ( '', { @input | 'input' } )

::= MD2 | MD4 | MD5 | SHA | SHA1


Output for MD2/MD4/MD5 is 16 bytes and for SHA/SHA1 is 20 bytes

Lets see an example of it


DECLARE @var VARCHAR(100)

SET @var = 'This is hashbytes example'

SELECT Hashbytes ('MD2', @var)

SELECT Hashbytes ('MD4', @var)

SELECT Hashbytes ('MD5', @var)

SELECT Hashbytes ('SHA', @var)

SELECT Hashbytes ('SHA1', @var)



No comments:

Post a Comment

Popular Posts