简体   繁体   中英

Can I identify a hash algorithm based on the initial key and output hash?

If I have both the initial key and the hash that was created, is there any way to determine what hashing algorithm was used?

For example:

  • Key : higher
  • Hash : df072c8afcf2385b8d34aab3362020d0
  • Algorithm : ?

By looking at the length, you can decide which algorithms to try. MD5 and MD2 produce 16-byte digests. SHA-1 produces 20 bytes of output. Etc. Then perform each hash on the input and see if it matches the output. If so, that's your algorithm.

Of course, if more than the "key" was hashed, you'll need to know that too. And depending on the application, hashes are often applied iteratively. That is, the output of the hash is hashed again, and that output is hashed… often thousands of times. So if you know in advance how many iterations were performed, that can help too.

There's nothing besides the length in the output of a cryptographic hash that would help narrow down the algorithm that produced it.

  1. The hash seems to contain only hexadecimal characters (each character represents 4bits)

  2. Total count is 32 characters -> this is a 128-bits length hash.

  3. Standard hashing algorithms that comply with these specs are: haval, md2, md4, md5 and ripemd128.

  4. Highest probability is that MD5 was used.

  5. md5("higher") != df072c8afcf2385b8d34aab3362020d0

  6. Highest probability is that some salt was used.

  7. Highest probability still remains MD5.

Well, given that there are a finite number of popular hash algorithms, maybe what you propose is not so ridiculous.

But suppose I asked you this:

If I have an input and an output, can I determine the function?

Generally speaking , no, you cannot determine the inner-workings of any function simply from knowing one input and one output , without any additional information.

// very, very basic illustration
if (unknownFunction(2) == 4) {
    // what does unknownFunction do?
    // return x + 2?
    // or return x * 2?
    // or return Math.Pow(x, 2)?
    // or return Math.Pow(x, 3) - 4?
    // etc.
}

Didn't match any of the common hashing algorithms:

http://www.fileformat.info/tool/hash.htm?text=higher

Perhaps a salt was added prior to hashing...

除了尝试一堆你知道并看到是否有任何匹配。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM