软件编程
位置:首页>> 软件编程>> C#编程>> C#实现的字符串转MD5码函数实例

C#实现的字符串转MD5码函数实例

作者:kagula  发布时间:2023-03-02 15:34:43 

标签:C#,字符串,MD5

本文实例讲述了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#程序设计有所帮助。

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com