读书人

关于MD5加密的不解

发布时间: 2012-09-06 10:37:01 作者: rapoo

关于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 "";        }    }} 

读书人网 >C#

热点推荐