2

I want to use the SQL Server HASHBYTES() function.

But I don't know how to get back the value passed to HASHBYTES...

5

This is not impossible but you should consider that the original data is lost and you cannot easily get the original data back from the hash value.

Once you get the hash H1 for a value V1, you only work with the hash value. Ie. knowing hash value H1 for value V1, you can match V1 with a second value V2 by computing H2 using the same hash algorithm. When V1 = V2 then H1 = H2. (see collision below)

From Hash function (Wikipedia):

A hash function is any function that can be used to map data of arbitrary size to data of fixed size. The values returned by a hash function are called hash values, hash codes, hash sums, or simply hashes. One use is a data structure called a hash table, widely used in computer software for rapid data lookup. Hash functions accelerate table or database lookup by detecting duplicated records in a large file. An example is finding similar stretches in DNA sequences. They are also useful in cryptography. A cryptographic hash function allows one to easily verify that some input data maps to a given hash value, but if the input data is unknown, it is deliberately difficult to reconstruct it (or equivalent alternatives) by knowing the stored hash value. This is used for assuring integrity of transmitted data, and is the building block for HMACs, which provide message authentication.

In theory, it may be possible to revert some mathematical functions used to compute some hashes. It is also possible to use dictionary and brute force with some tools. But in most cases, it would be too difficult or it would take too long to get them back.

There is also no guarantee that you will get the same value back. It may also get a value with the same hash because hash are fixed length values and input data is of infinite length. See Hash Collision (Wikipedia):

a collision or clash is a situation that occurs when two distinct pieces of data have the same hash value, checksum, fingerprint, or cryptographic digest

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.