本文实例讲述了C#实现的字符串转MD5码函数。,具体如下:
/*
测试环境: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
希望本文所述对大家C#程序设计有所帮助。
注:相关教程知识阅读请移步到c#教程频道。










