ASP.NET实现MD5加密算法

来源:互联网 发布:网络视频课怎么刷 编辑:程序博客网 时间:2024/05/20 20:01
public string Encry(string str,int code)
  {
   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,"MD5").ToLower();
   }
    else
   {
   return "00000000000000000000000000000000";
   }
  }
 
其实在.net 有一个最简单实现MD5的方法

public static string MD5(string toCryString)
{
return FormsAuthentication.HashPasswordForStoringInConfigFile(toCryString, "MD5");