MD5 加密

       /// <summary>
       /// Web 转换MD5
       /// </summary>
       /// <param name="str">字符</param>
       /// <param name="code">32或64位</param>
       /// <returns></returns>
        public static string MD5(string str, int code)
        {

            if (code == 16)
            {
                return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower().Substring(8, 16);
            }

            if (code == 32)
            {
                return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5");
            }

            return "00000000000000000000000000000000";
        }




 //MD5 正常加密  
 public static string HashString(string str) { 
            MD5   md5=MD5.Create();
            byte[] source = md5.ComputeHash(Encoding.Default.GetBytes(str));
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < source.Length; i++)
            {
                sb.Append(source[i].ToString("x"));
            }

            return sb.ToString(); 
        }






 

posted @ 2014-07-28 10:40  SSS.M.AAA  阅读(640)  评论(0编辑  收藏  举报