简体   繁体   English

MD5在PHP和JAVA中给出了不同的结果

[英]MD5 is giving different results in PHP & JAVA

In my Program, I load a file to my Server using Ftp out of a Java Program and then I compare the MD5-sum. 在我的程序中,我使用Ftp从Java程序加载文件到我的服务器,然后我比较MD5和。

The upload works fine, and I get the same md5 sums. 上传工作正常,我得到相同的md5总和。 But the php-version has a "0" before the same md5-sum. 但是php-version在相同的md5-sum之前有一个“0”。 Why is this so? 为什么会这样?

Php: 0e9e9399840d9a9368b53d3df98a6a2f
Java: e9e9399840d9a9368b53d3df98a6a2f

They're the same, it's just PHP has padded the value with an extra 0 in front so it's always 16 characters. 它们是相同的,只是PHP在前面加了一个额外的0来填充值,所以它总是16个字符。

Think of the hash as a number in hexadecimal - it can be padded out so it's always the same number of digits (because it's never greater than 16 digits), but it doesn't have to be. 将散列视为十六进制的数字 - 它可以填充,因此它总是相同的数字位数(因为它永远不会超过16位),但它不一定是。 It's a bit like comparing the numbers 209 and 0209 . 这有点像比较数字2090209

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

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