using System.Security.Cryptography;
// 32 位
public String md5(String s)
{
MD5 md5 = new MD5CryptoServiceProvider();
byte[] bytes = System .Text .Encoding .UTF8 .GetBytes(s);
bytes = md5 .ComputeHash(bytes);
md5 .Clear();
string ret = "";
for (int i=0 ; i<bytes .Length ; i++)
{
ret += Convert .ToString(bytes[i] , 16) .PadLeft(2 , '0');
}
return ret .PadLeft(32 , '0');
}
// 16 位
public string GetMd5Str(string ConvertString)
{
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
string t2 = BitConverter .ToString(md5 .ComputeHash(UTF8Encoding .Default .GetBytes(ConvertString)) , 4 , 8);
t2 = t2 .Replace("-" , "");
return t2;
}