简体   繁体   中英

How to combine md5 hashes to of byte array to get equalent md5 hash of combined array

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?

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?

密码学专家可能有能力使用值的部分MD5哈希值来获取有关完整值的MD5哈希值的一些信息,但出于实际目的,获取值的MD5哈希值的唯一方法是计算MD5从该值散列。

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