C# · 12月 26, 2021

C#生成MD5的函数代码

复制代码 代码如下:
public static string GetMD5(string sDataIn)
{
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
byte[] bytValue,bytHash;
bytValue = System.Text.Encoding.UTF8.GetBytes(sDataIn);
bytHash = md5.ComputeHash(bytValue);
md5.Clear();
string stemp = “”;
for (int i = 0; i < bytHash.Length; i++)
{
stemp += bytHash[i].ToString(“X”).PadLeft(2,’0′);
}
return stemp.ToLower();
}