MD5加密的两种方式笔记。

第一种方式是使用:
System.Web.Security空间下的相应类和方法加密,示例:
public string GetMD5(string s,int len)
{
   
return FormsAuthentication.HashPasswordForStoringInConfigFile(s,"MD5").Substring(0,len).ToLower();
}
第二种方式:
public string GetMD5(string s,int len)
{
  System.Security.Cryptography.MD5 md5
=System.Security.Cryptography.MD5.Create();
  
byte[] bytes=System.Text.Encoding.UTF8.GetBytes(s);
bytes
=md5.ComputeHash(bytes);
return System.BitConverter.ToString(buffer).Replace("-""").Substring(0,len).ToLower();
}
posted @ 2008-06-03 09:38  mcjeremy  阅读(717)  评论(0编辑  收藏  举报
------------------------------------ 心静似高山流水不动,心清若巫峰雾气不沾 ------------------------------------