新一篇: Microsoft .Net 框架 SDK 快速入门教程
1 可以用于密码加密,长度32位。
/// <summary>
/// md5加密算法
/// </summary>
/// <param name="strIN"></param>
/// <returns></returns>
private string MD5Encrypt(string strIN)
{
System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] bytValue, bytHash;
bytValue = System.Text.Encoding.UTF8.GetBytes(strIN);
bytHash = md5.ComputeHash(bytValue);
md5.Clear();
string sTemp = "";
for (int i = 0; i < bytHash.Length; i++)
{
sTemp += bytHash[i].ToString("x").PadLeft(2, '0');
}
if (sTemp.Length > 32)
{
sTemp = sTemp.Substring(0, 32);
}
return sTemp;
}
/// md5加密算法
/// </summary>
/// <param name="strIN"></param>
/// <returns></returns>
private string MD5Encrypt(string strIN)
{
System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] bytValue, bytHash;
bytValue = System.Text.Encoding.UTF8.GetBytes(strIN);
bytHash = md5.ComputeHash(bytValue);
md5.Clear();
string sTemp = "";
for (int i = 0; i < bytHash.Length; i++)
{
sTemp += bytHash[i].ToString("x").PadLeft(2, '0');
}
if (sTemp.Length > 32)
{
sTemp = sTemp.Substring(0, 32);
}
return sTemp;
}