AS3 和 Java 之间的 MD5 ByteArray 差异
我正在尝试将一个库从 Java 移植到 AS3,并且我正在使用 MD5 函数。我正在使用作为项目一部分找到的 MD5 库:http://code.google。 com/p/as3crypto/。
我得到的长度是正确的,大约一半的值是正确的。具有讽刺意味的是,正确的值也位于正确的位置。只有负值是错误的。例如,两个哈希生成:
Java: [127, -16, 107, -93, -103, 1, 104, -5, -111, 12, -126, -91, 61, 32, -67, 61]
AS3: [127, 240, 107, 163, 153, 1, 104, 251, 145, 12, 130, 165, 61, 32, 189, 61]
我已经验证他们正在散列的源字符串是完全相同。不确定可以以不同的方式实施什么,或者我需要在自己的实施中改变什么。
I'm trying to port a library from Java into AS3, and I'm down to the MD5 function. I'm using the MD5 library found as part of the project here: http://code.google.com/p/as3crypto/.
I'm getting the length correct, and about half of the values are correct. The ironic thing is the correct values are in the correct spot as well. Only the negative values are wrong. As an example, the two hashes produce:
Java: [127, -16, 107, -93, -103, 1, 104, -5, -111, 12, -126, -91, 61, 32, -67, 61]
AS3: [127, 240, 107, 163, 153, 1, 104, 251, 145, 12, 130, 165, 61, 32, 189, 61]
I've verified that the source String that they are hashing off are the exact same. Not sure what could be implemented differently, or what I need to change in my own implementation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
-93 和 163 是同一件事
发生的情况是,您将位字符串打印为带符号的数字,并且您没有使用大脑中运行的二进制补码过滤器来评估结果。
提示:注意所有“不正确”值都是
-(256 -(“正确”值))
吗?-93 and 163 are the same thing
What's happening is that you are printing bit strings as signed numbers, and you aren't evaluating the results with a twos-complement-filter running in your brain.
Hint: notice how all your "incorrect" values are
-(256 -("correct" value))
?事实证明,这个问题正是上面 digitalross 提到的,但要求我进入 MD5 类,并处理所有 uint 类型的实例,并将它们移至 int 类型。
谢谢指点
Turns out the issue is exactly what was mentioned by digitalross above, but required that I go into the MD5 class, and work through all of the instances of type uint and move them to be of type int instead.
Thanks for the pointer