代码改变世界

关于MD5加密

2009-07-28 17:43  AkingShoot  阅读(182)  评论(0编辑  收藏  举报

引用命名空间
using System.Web.Security; 
//MD5加密后长度是32位  
FormsAuthentication.HashPasswordForStoringInConfigFile("abc","md5")  
 
 
//SH1加密后长度是40位  
FormsAuthentication.HashPasswordForStoringInConfigFile("abc", "sha1") 


例子:
public string EncryptStr(string PWD, int Format)
    {
        string str = "";
        switch (Format)
        {
            case 0:
                str = FormsAuthentication.HashPasswordForStoringInConfigFile(PWD, "SHA1");
                break;
            case 1:
                str = FormsAuthentication.HashPasswordForStoringInConfigFile(PWD, "MD5");
                break;
        }
        return str;
    }