public string UserMd5(string md5)
{
System.Security.Cryptography.MD5CryptoServiceProvider md = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] value, hash;
value = System.Text.Encoding.UTF8.GetBytes(md5);
hash = md.ComputeHash(value);
md.Clear();
string temp = "";
for (int i = 0, len = hash.Length; i < len; i++)
{
temp += hash[i].ToString("X").PadLeft(2, '0');
}
return temp;
}
本文介绍了一种使用C#语言实现字符串MD5加密的具体方法。通过实例代码展示了如何将输入的字符串转换为UTF-8编码的字节数组,再利用MD5算法计算哈希值,并最终将哈希值转换为十六进制字符串形式。
527

被折叠的 条评论
为什么被折叠?



