Search code examples
c#shahmacsha1

Is it possible to check if a hash was generated using SHA1 and is a valid hash?


I ran into an issue where I want to validate a hash which was generated using SHA1. Is it possible to reverse engineer and figure out if the hash was generated using HMACSHA1 algo?


Solution

  • No, there is nothing in a hash code that can tell you what algorithm was used to create it. Any strong hash code algorithm is specifically designed to not contain any traceable meta data in the hash code. There is no specific markers that identifies the hash code as being a hash code, or what kind of algorithm was used.

    Basically a hash algorithm tries to create a strong pseuo-random number using all the input as seed. The output is just as random as possible, there are no recognisable patterns that could be used to identify the input data or the algorithm.

    If you have the input data that was used to create the hash code, you could recreate it and compare the results. However, if just a single bit in the input is different you get a completely different hash code, so the input has to be exactly the same.