Home > Backend Development > PHP Tutorial > Convert java version MD5 to php version

Convert java version MD5 to php version

巴扎黑
Release: 2016-11-09 13:19:07
Original
1883 people have browsed it

java code

public static String encryptMD5_Salt(String content) {
    String resultString = "";
    String appkey = "acdf,kef";
    byte[] a = appkey.getBytes();
    byte[] datSource = content.getBytes();
    byte[] b = new byte[a.length + 4 + datSource.length];
    int i;
    for (i = 0; i < datSource.length; i++) {
        b[i] = datSource[i];
    }
    b[i++] = (byte) 143;
    b[i++] = (byte) 112;
    b[i++] = (byte) 131;
    b[i++] = (byte) 143;
    for (int k = 0; k < a.length; k++) {
        b[i] = a[k];
        i++;
    }
    try {
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        md5.update(b);
        resultString = new HexBinaryAdapter().marshal(md5.digest());
    } catch (Exception e) {
        e.printStackTrace();
    }
    return resultString.toLowerCase();
}
Copy after login

php code:

function javaMd5($data) {
   assert(is_array($data));
   $dataString = byteArrayToString($data);
   $hashString = md5($dataString);
   return $hashString;
}
function byteArrayToString($b) {
   assert(is_array($b));
   $asciiString = &#39;&#39;;
   for ($i = 0; $i < count($b); $i++) {
      $asciiString .= chr($b[$i]);
   }
   return $asciiString;
}
$re=array_merge
   (unpack("c*", pack("a*", $content)),
   pack("c", pack("l", 143)),
   unpack("c", pack("l", 112)),
   unpack("c", pack("l", 131)),
   unpack("c", pack("l", 143)),
   unpack("c*", pack("a*", "acdf,kef"))
   );
$re = javaMd5($re);
Copy after login


Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Install JAVA
From 1970-01-01 08:00:00
0
0
0
Unable to install java
From 1970-01-01 08:00:00
0
0
0
Can java be used as the backend of the web?
From 1970-01-01 08:00:00
0
0
0
Is this in Java language?
From 1970-01-01 08:00:00
0
0
0
Help: JAVA encrypted data PHP decryption
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template