C#字符串转MD5码函数

来源:互联网 发布:002174游族网络雪球 编辑:程序博客网 时间:2024/06/10 03:25
/*测试环境:WinXP SP3、Visual Studio 2008 SP1、Visual Studio 2010 SP1更新日期:2014-04-23*/public string CalculateMD5Hash(string input){    MD5 md5 = System.Security.Cryptography.MD5.Create();    byte[] inputBytes = System.Text.Encoding.UTF8.GetBytes(input);    byte[] hash = md5.ComputeHash(inputBytes);    // step 2, convert byte array to hex string    StringBuilder sb = new StringBuilder();    for (int i = 0; i < hash.Length; i++)    {sb.Append(hash[i].ToString("X2"));    }    return sb.ToString();}//end func

0 0
原创粉丝点击