JAVA版:
private static string md5Digest(string spId, string spPassword, string timeStamp)
{
try
{
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(spId.getBytes());
md.update(spPassword.getBytes());
md.update(timeStamp.getBytes()); byte[] b = md.digest();
String result = "";
String temp = ""; for (int i = 0; i < 16; i++)
{
temp = Integer.toHexString(b[i] & 0xFF);
if (temp.length() == 1)
temp = "0" + temp;
result = result + temp;
} result = result.toUpperCase(); return result;
}
catch (NoSuchAlgorithmException e)
{
e.printStackTrace();
return null;
}
catch (Exception e)
{
e.printStackTrace();
} return null;
}我需要用C#实现。结果必须跟这个JAVA方法一样的 求高手,求大侠 相助好久没来了。没分了希望各位大哥别嫌弃。。
private static string md5Digest(string spId, string spPassword, string timeStamp)
{
try
{
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(spId.getBytes());
md.update(spPassword.getBytes());
md.update(timeStamp.getBytes()); byte[] b = md.digest();
String result = "";
String temp = ""; for (int i = 0; i < 16; i++)
{
temp = Integer.toHexString(b[i] & 0xFF);
if (temp.length() == 1)
temp = "0" + temp;
result = result + temp;
} result = result.toUpperCase(); return result;
}
catch (NoSuchAlgorithmException e)
{
e.printStackTrace();
return null;
}
catch (Exception e)
{
e.printStackTrace();
} return null;
}我需要用C#实现。结果必须跟这个JAVA方法一样的 求高手,求大侠 相助好久没来了。没分了希望各位大哥别嫌弃。。
不懂JAVA
//winform
public static string StringToMD5Hash(string inputString)
{
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
byte[] encryptedBytes = md5.ComputeHash(Encoding.ASCII.GetBytes(inputString));
StringBuilder sb = new StringBuilder();
for (int i = 0; i < encryptedBytes.Length; i++)
{
sb.AppendFormat("{0:x2}", encryptedBytes[i]);
}
return sb.ToString();
} //webform
public static string md5(string pwd)
{
string md5pwd = FormsAuthentication.HashPasswordForStoringInConfigFile(pwd, "MD5");
return md5pwd;
}
有相关的方法 可以直接用