Skip to content
Advertisement

What will be the Android/Java equivalent of MD5 function in PHP?

I am calculating the MD5 in Android/Java as follows:

JavaScript

However there’s a mismatch with PHP’s md5() function.

MD5 - PHP  - Raw Value - catch12 - 214423105677f2375487b4c6880c12ae
MD5 - JAVA - Raw Value - catch12 - 214423105677f2375487b4c688c12ae

How is this caused and how can I solve it so that the both Android/Java and PHP generate exactly the same MD5 hash?

Advertisement

Answer

You need to prefix hex value with 0 when the byte is less than 0x10. Here’s a full example:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement