Skip to content
Advertisement

Convert SQL result from Hash to Varchar

I have some data in an SQL table that is hashed, and am trying to convert these variables back to a string, however everything I get back is gibberish.

I have tried all suggestions on Stack Overflow, including removing all the sequential double zeros ’00’.

I don’t know what the unhash-ed variables look like, but I assume it will be a string variable. How would we even know where to start determining what sort of hash was applied to this field in the first place?

Any help or guidance is very appreciated.

My attempts so far have been:

EDIT – Have also attempted BASE64 DECODE on SQL- https://dba.stackexchange.com/questions/191273/decode-base64-string-natively-in-sql-server

Advertisement

Answer

If this is really a hash value, there is no realistic chance to revert the value to its value.

But, looking at your values, I doubt, that these are really hash values. It is very unusual to get such close binary representations. Try to use any hash function against any value. You would not get results such similar…

Without any knowledge about your needs, you might try to take the binary value as any (16 byte?) type or chain of smaller types. Here I use BIGINT (two 8-byte-values), you can try UNIQUEIDENTIFIER, or you might take this as a chain of 16 1-byte values, a chain of 8 2-byte values or any other viable interpretation.

One guess: This might be a combined key of two numbers. Might be a tenant and a table key in a binary combination. It is obvious, that the values consist of very similar numbers. Those with 16 bytes include rather near values.

It might help to tell us more about your problem’s background…

UPDATE

Taking this as chain of 4-byte-int-values returns rather interesting results:

The result

int1 and int3 seems to be the same value. This points to any kind of combined key…

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement