为啥我用MD5加密后的密文全部是数字?
为啥我用MD5加密后的密文全部是数字?好像跟一般的MD5加密网站的密文不同啊,我的加密方法C#代码如下,请问要怎么改?
public string GetMD5(string strpwd)
{
MD5 md5 = new MD5CryptoServiceProvider(); //加密服务提供类
byte[] bPwd = Encoding.Default.GetBytes(strpwd); //将输入的密码转换成字节数组
byte[] bMD5 = md5.ComputeHash(bPwd); //计算指定字节数组的哈希值
md5.Clear(); //释放加密服务提供类的所有资源
StringBuilder sbMD5Pwd = new StringBuilder();
for (int i = 0; i < bMD5.Length; i++) //将加密后的字节转换成字符串
{
sbMD5Pwd.Append(bMD5[i].ToString());
}
return sbMD5Pwd.ToString();
}
[解决办法]
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; }