我只想使用php md5函数(代码),它与下面的java代码生成相同的结果......
普通的php md5函数没有给出与这个java代码相同的结果..
private static final String md5(String string) {
try {
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
messageDigest.update(string.getBytes());
byte[] arrby = messageDigest.digest();
StringBuffer stringBuffer = new StringBuffer();
int n = 0;
block3 : do {
if (n >= arrby.length) {
return stringBuffer.toString();
}
String string2 = Integer.toHexString(255 & arrby[n]);
do {
String string3;
if (string2.length() >= 2) {
stringBuffer.append(string2);
++n;
continue block3;
}
string2 = string3 = "0" + string2;
} while (true);
} while (true);
}
catch (NoSuchAlgorithmException var1_7) {
var1_7.printStackTrace();
return "";
}
}
代码已编辑...以及给出的示例....
String =“fpwdxx-xx0xx-xx”+“8420474066”+“xx-xx”+“2.9”+“xx-xx”+“2016-09-14 21:13:25”+“xx-xx “+” AIRTEL “+” XX-XX “+” “+” XX-XX “+” 26b792f77e6f5157 “+” XX-XX “+” 911364603150705 “+” XX-XX “+” A52 + “+” XX-XX” + “4.2.2” + “z1t998044Fgrt ... d”;
Java结果:cfcb292130f3aa3cd49eed180e3d76a3
PHP结果:dd7e471b1a66a691097017c8de 2783a3
答案 0 :(得分:0)
php有自己的md5函数:http://php.net/manual/en/function.md5.php
md5($string)
这是标准的实现,但是php在前面添加了一个额外的0值,所以它总是16个字符,所以你可以检查这个