java生成的md5怎么同c#生成的md5值不一样????

zhyx21century 2007-04-10 05:13:40
asp.net中
FormsAuthentication.HashPasswordForStoringInConfigFile("jack","md5");
其值为4FF9FC6E4E5D5F59C4F2134A8CC96D1
c#中
string cl = "jack";
string pwd = "";
MD5 md5 = MD5.Create();//实例化一个md5对像
byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(cl));
for (int i = 0; i < s.Length; i++)
{
pwd = pwd + s[i].ToString("X");
}
pwd为4FF9FC6E4E5D5F59C4F2134A8CC96D1
而java中

import java.security.*;


public class MD5_ok {

public final static String MD5(String s) {
char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f' };
try {
byte[] strTemp = s.getBytes();
MessageDigest mdTemp = MessageDigest.getInstance("MD5");
mdTemp.update(strTemp);
byte[] md = mdTemp.digest();
int j = md.length;
char str[] = new char[j * 2];
int k = 0;
for (int i = 0; i < j; i++) {
byte byte0 = md[i];
str[k++] = hexDigits[byte0 >>> 4 & 0xf];
str[k++] = hexDigits[byte0 & 0xf];
}
return new String(str);
} catch (Exception e) {
return null;
}
}

public static void main(String[] args) {
// MD5_Test aa = new MD5_Test();

System.out.print(MD5_ok.MD5("jack"));
}
}
返回值为
73c18c59a39b18382081ec00bb456d43

这个是什么原因???
...全文
821 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
ChDw 2007-04-11
  • 打赏
  • 举报
回复
byte[] md = ..
StringBuffer buff = new StringBuffer();
for (int i = 0; i < j; i++) {
String str = Integer.toHexString(md[i] & 0xFF);
buff.append(str.length() == 1 ? "0" + str : str);
}
buff.toString();
zhyx21century 2007-04-11
  • 打赏
  • 举报
回复
。。。java出来好像是4ff9fc6e4e5d5f590c4f2134a8cc96d1。。。郁闷了。。昨天怎么不对???
zhyx21century 2007-04-11
  • 打赏
  • 举报
回复
???不会吧
binny 2007-04-11
  • 打赏
  • 举报
回复
java出来的是
4ff9fc6e4e5d5f590c4f2134a8cc96d1
zhyx21century 2007-04-11
  • 打赏
  • 举报
回复
哎。。就没人知道了么
steven_cheng 2007-04-10
  • 打赏
  • 举报
回复
MD5加密后的字节码是一样的,不一样的是字节码转换成字符的地方。字节码不可能都是字符,有可能是一些不能显示的控制符什么的,所以每个程序对这个转换都不一样。找到它不一样的地方,改成一致的。或者,把密码验证都交给c#
zhyx21century 2007-04-10
  • 打赏
  • 举报
回复
怎么解决呢。。。两套系统 一个是donet一个是java的。密码是c#md5加密过的。头大了。。
zuguanqun 2007-04-10
  • 打赏
  • 举报
回复
可能是算法不一样

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧