Reputation: 7
I have two byte arrays lets say A and B. And I computed MD5 Hash AH and BH for them respectively. Now if I Combine these arrays A and B to AB, and compute MD5 hash as ABH what whould be the way to combine AH and BH to equate ABH?
Upvotes: 0
Views: 764
Reputation: 11658
Based on your comments that you don't need a cryptographic hash, but just some kind of "fingerprint" to give a certain degree of hash = data assurance, then here's one possibility:
The simplest hash of all is to just XOR (exclusive-or) the data against itself. So for an 8-byte hash, you just walk over the data and XOR every 8 bytes together, producing an 8-byte hash. This provides a very high degree of certainty, unless the "bad guys" know how you do the hashing, then it is easy to fake.
If you concatenate two data arrays, A and B, then as long as A is a multiple of 8 in length, or if it's acceptable to place zeros padding between A and B so A + padding is a multiple of 8, then the combined hash will be (hash of A) XOR (hash of B). (At least, that's what I learned 50 years ago, if I remember right.)
Edit:
Just found this: Why is XOR the default way to combine hashes?
Upvotes: 1
Reputation: 3895
It's possible that cryptography experts may have some ability to use partial MD5 hashes of a value to get some information about the MD5 hash for the complete value, but for practical purposes the only way to get the MD5 hash of a value is to compute the MD5 hash from that value.
Upvotes: 0