日期:2014-05-19  浏览次数:20406 次

求一MD5加密码方法!!!!1
求一MD5加密码方法!!!!1

------解决方案--------------------
#region MD5_ByteEncrypt
/// <summary>
/// 加密处理用户密码
/// </summary>
/// <param name= "encryptString "> 需要加密的字符串 </param>
/// <returns> 加密后的字符串 </returns>
public static string MD5_ByteEncrypt(string encryptString)
{
Byte[] clearBytes = new UnicodeEncoding().GetBytes(encryptString);
Byte[] hashedBytes = ((HashAlgorithm)CryptoConfig.CreateFromName( "MD5 ")).ComputeHash(clearBytes);
return BitConverter.ToString(hashedBytes);
}

public static string MD5_CryptoService(string encrypString, int DATA_SIZE)
{
// System.Security.Cryptography.MD5CryptoServiceProvider名称空间

byte[] data = new byte[DATA_SIZE]; //128
// This is one implementation of the abstract class MD5.
MD5 md5 = new MD5CryptoServiceProvider();
byte[] result = md5.ComputeHash(data);
return BitConverter.ToString(result);

}

public static string pwdSecurity(string pwd)
{
return FormsAuthentication.HashPasswordForStoringInConfigFile(pwd, "md5 ").ToLower();
}
#endregion
------解决方案--------------------
有意思
被类库迷晕了头,.net版块很小看到讨论.net里的算法了。

------解决方案--------------------
.net类库中有很多种方法可以实现
并且有一个专门的MD5类,查一下msdn吧
------解决方案--------------------
using System.Web.Security;

string hashPwd = FormsAuthentication.HashPasswordForStoringInConfigFile(pwd, "MD5 ");

//pwd 加密前字符串 hashPwd 加密后字符串

此外还支持 SHA1 加密
...(pwd, "SHA1 ");
------解决方案--------------------
引用一下,就可以直接用MD5的 加密方法