在云那方

首页 新随笔 联系 订阅 管理
   //添加引用
   //using System.Text;
   //using System.Security.Cryptography;
   //密码加密算法流程
   //将密码按以下方式加密之后,存进数据库
   //在验证用户身份时再加密码加密和数据库密码进行比较
   
public string Encrypt(string password) 
   
{
    password 
= password.ToLower();
    Byte[] clearBytes 
= new UnicodeEncoding().GetBytes(password);
    Byte[] hashedBytes 
= ((HashAlgorithm) CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes);

    
return BitConverter.ToString(hashedBytes);
   }


另一种和asp生成值一样的代码:
protected string UserMd5(string str) 
{
    
byte[] result = Encoding.Default.GetBytes(str);
    MD5 md5 
= new MD5CryptoServiceProvider();
    
byte[] output = md5.ComputeHash(result);
    
return BitConverter.ToString(output).Replace("-""");  
}
 
posted on 2008-07-04 14:15  Rich.T  阅读(660)  评论(0编辑  收藏  举报