码迷,mamicode.com
首页 > Windows程序 > 详细

c#字符串MD5加密GetMD5Hash

时间:2014-10-29 19:13:17      阅读:280      评论:0      收藏:0      [点我收藏+]

标签:blog   http   os   ar   for   sp   div   log   html   

/// <summary>
        /// 把字符转换成MD5
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static string GetMD5Hash(String str)
        {
                   //把字符串转换成字节数组
                   byte[] buffer = Encoding.Default.GetBytes(str);

                  MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
                   //md5加密
                   byte[] cryptBuffer = md5.ComputeHash(buffer);
                   string s = "";
                   //把每一个字节 0-255,转换成两位16进制数     
                   for (int i = 0; i < cryptBuffer.Length; i++)
                   {
                           //大X转黄的是大写字母,小X转换的是小写字母
                           s += cryptBuffer[i].ToString("x2");
                   }
              return s;
        } 

 转自:http://www.nbcoder.net/thread-271-1-1.html

c#字符串MD5加密GetMD5Hash

标签:blog   http   os   ar   for   sp   div   log   html   

原文地址:http://www.cnblogs.com/xiaoshi212/p/4060035.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!