The result of php md5 is different from that of java.

problem description:
because when the interface is docked, the other party only provides the java interface, and the md5 encryption signature is required when the interface is called, and the signature verification fails all the time. Finally, it is found that the result of the Md5 of both sides is different
.
java md5?javaPHP?

str="aId=1&action=queryWeizhang&carNo=A12345&carType=02&mId=1&key"

java:385400B2F19F85CA5314AC521C7990A1
php :5DA911F422619237A2085332861DDC15

resolved:
$param = array_map ("urlencode", $param);

    $param["aId"] = $this->aId;
    $param["sign"] = $this->sign($param);
    ksort($param);
    $base64 = base64_encode(json_encode($param));
Php
Feb.09,2022

MD5 has nothing to do with language. After testing, JAVA is also 5DA911F422619237A2085332861DDC15

.
import java.io.*;
import java.security.MessageDigest;

class test  
{
    private static String MD5(String s) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] bytes = md.digest(s.getBytes("utf-8"));
            return toHex(bytes);
        }
        catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

private static String toHex(byte[] bytes) {

    final char[] HEX_DIGITS = "0123456789ABCDEF".toCharArray();
    StringBuilder ret = new StringBuilder(bytes.length * 2);
    for (int i=0; i<bytes.length; iPP) {
        ret.append(HEX_DIGITS[(bytes[i] >> 4) & 0x0f]);
        ret.append(HEX_DIGITS[bytes[i] & 0x0f]);
    }
    return ret.toString();
}

    public static void main (String[] args) throws java.lang.Exception
    {
        System.out.println(test.MD5("aId=1&action=queryWeizhang&carNo=A12345&carType=02&mId=1&key"));
    }
}

search for a lot of related content.
JAVA and PHP md5's encrypted values are inconsistent

Menu