日期:2014-05-18  浏览次数:20942 次

关于MD5加密的疑惑
代码如下
C# code

 public string md5(string str, int code)  //code 16 或 32  
    {
        if (code == 16) //16位MD5加密(取32位加密的9~25字符)  
        {
            return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower().Substring(8, 16);
        }

        if (code == 32) //32位加密  
        {
            return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str.Trim(), "MD5").ToString();
                   
        }

        return "00000000000000000000000000000000";
    }
}



我选择的是32位的加密为什么出来后是16位的啊?

------解决方案--------------------
C# code

using System.Web.Security;

namespace Usb_Server
{
    public class ToMd5
    {
        /// <summary>
        /// 给密码加密
        /// </summary>
        /// <param name="str"></param>
        /// <param name="code"></param>
        /// <returns></returns>
        public string md5(string str, int code)
        {
            if (code == 16)  //16位MD5加密(取32位加密的9~25字符)
            {
                return FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower().Substring(8, 16);
            }

            if (code == 32)   //32位MD5加密
            {
                return FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower();
            }

            return "";
        }

    }
}