导航

dotNET中有关MD5加密的一点笔记

Posted on 2005-08-10 16:43  Jim  阅读(322)  评论(0)    收藏  举报
DotText中使用的
        public static string Encrypt(string password) 
        
{
            
// Force the string to lower case
            
//
            password = password.ToLower();

            Byte[] clearBytes 
= new UnicodeEncoding().GetBytes(password);
            Byte[] hashedBytes 
= ((HashAlgorithm) CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes);

            
return BitConverter.ToString(hashedBytes);
        }

Asp.net可用的
string strMd5En = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(password.ToLower(),"MD5");

HashPasswordForStoringInConfigFile方法没有指定编码,应该是使用了Web.config的系统编码