简体   繁体   English

如何将md5哈希组合到字节数组以获得相等的md5哈希组合数组

[英]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. 我有两个字节数组,可以说A和B。分别为它们计算了MD5哈希值AH和BH。 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? 现在,如果我将这些数组A和B组合为AB,并将MD5哈希计算为ABH,那么将AH和BH组合为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. 最简单的哈希是将数据与自身进行XOR(异或)运算。 So for an 8-byte hash, you just walk over the data and XOR every 8 bytes together, producing an 8-byte hash. 因此,对于8字节的哈希,您只需遍历数据并每8个字节进行XOR运算,即可产生8字节的哈希。 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). 如果连接两个数据数组A和B,则只要A的长度是8的倍数,或者如果在A和B之间放置零填充是可接受的,那么A +填充是8的倍数,则合并的哈希将为(A的哈希)XOR(B的哈希)。 (At least, that's what I learned 50 years ago, if I remember right.) (如果我没记错的话,至少这是我50年前学到的。)

Edit: 编辑:

Just found this: Why is XOR the default way to combine hashes? 刚刚发现: 为什么XOR是组合哈希的默认方法?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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