简体   繁体   中英

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.

The upload works fine, and I get the same md5 sums. But the php-version has a "0" before the same md5-sum. 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.

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. It's a bit like comparing the numbers 209 and 0209 .

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