首页 > 编程 > C# > 正文

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

2019-10-29 21:24:54
字体:
来源:转载
供稿:网友

本文实例讲述了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#教程频道。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表