MessageDigest mdInst = MessageDigest.getInstance("MD5");
byte[] md = mdInst.digest(value.getBytes());//value为认证的原文
String md5 = "";
for(int i=0;i<md.length;i++)
{
md5+=("" + "0123456789ABCDEF".charAt(0xf & md[i] >> 4 + "0123456789ABCDEF".charAt(md[i] & 0xf));
}
byte[] Buffer = Encoding.Default.GetBytes(value);
MD5 md5 = MD5.Create();
byte[] tempMD5Value = md5.ComputeHash(Buffer);
string strMD5Value = string.Empty;
for (int i = 0; i < tempMD5Value.Length; i++)
{
strMD5Value += ("" + md5Str.Substring(0xf & tempMD5Value[i] >> 4, 1) + md5Str.Substring(tempMD5Value[i] & 0xf, 1));
}
不能修改JAVA,怎么改下C#让加密结果一样呀。
------解决方案--------------------
"" + "0123456789ABCDEF"这个是为了安全而加上自己的字符集然后再MD5吗?
------解决方案--------------------
byte[] Buffer = Encoding.Default.GetBytes(value);//这里的Default应该是ANSI,Java就不懂了,一般C#都是直接用内部的md5加密算法
System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(text,"MD5");
------解决方案--------------------
string value = "1234567";
string md5Str = "0123456789ABCDEF";
System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] buffer = md5.ComputeHash(Encoding.Default.GetBytes(value));
string strMD5Value = string.Empty;
for (int i = 0; i < buffer.Length; i++)
{
int a = 0xf & buffer[i] >> 4;
int b = buffer[i] & 0xf;
strMD5Value += md5Str.Substring(0xf & buffer[i] >> 4, 1) + md5Str[buffer[i] & 0xf];
}
MessageBox.Show(strMD5Value);//FCEA920F7412B5DA7BE0CF42B8C93759
try {
MessageDigest mdInst = MessageDigest.getInstance("md5");
String value = "1234567";
byte[] md = mdInst.digest(value.getBytes());// value为认证的原文
String md5 = "";
for (int i = 0; i < md.length; i++) {
int a = 0xf & md[i] >> 4;
int b = md[i] & 0xf;
md5+=("" + "0123456789ABCDEF".charAt(0xf & md[i] >> 4) + "0123456789ABCDEF".charAt(md[i] & 0xf));
}
System.out.println(md5);//FCEA920F7412B5DA7BE0CF42B8C93759
} catch (Exception e) {
}
------解决方案--------------------
你仔细对照一下你贴的java代码和我的java代码中的for循环,看看有什么不同(注意括号)
------解决方案--------------------
我日 自己发的怎么不能删呢