js函数转java函数
js代码://将MD5的值转为16进制
function hexchar2bin(str) {
var arr = [];
for (var i = 0; i < str.length; i = i + 2) {
arr.push("\\x" + str.substr(i, 2))
}
arr = arr.join("");
eval("var temp = '" + arr + "'");
return temp
}
function getCoe(){
var M="111111"
var I = hexchar2bin(md5(M));
var H = md5(I );
return H;
}
java代码:
public static String getCode(){
String M = "111111";
String I = hexchar2bin(getMD5(M));
String h = getMD5(I);
return h;
}
public static String hexchar2bin(String hex){
StringBuffer sb = new StringBuffer();
for(int i=0;i<hex.length();i=i+2){
String temp = hex.substring(i, i+2);
int in = Integer.parseInt(temp,16);
sb.append((char)in);
}
return sb.toString();
}
为什么结果不一致呢?js的函数 hexchar2bin结果返回是MD5结果转为16进制字符显示结果吗?
js应该怎么转换成java呢,谢谢啦!
补充:Java , Java SE