在System.Web.Security名称空间中的FormsAuthentication类中提供了HashPasswordForStoringInConfigFile方法,这个方法的目的正如它的名字所提示的,就是要加密存储在Form表单的口令。HashPasswordForStoringInConfigFile方法使用起来非常简单,它支持用于加密字符串的“SHA1”和“MD5”散列算法。
  epwd=FormsAuthentication.HashPasswordForStoringInConfigFile(pwd.Text, "SHA1");
  //epwd=FormsAuthentication.HashPasswordForStoringInConfigFile(pwd.Text, "MD5");

解决方案 »

  1.   

    public string GetOf(string myString) 
    {
             MD5 md5  = new MD5CryptoServiceProvider();
    byte[] fromData = System.Text.Encoding.Unicode.GetBytes(myString);
    byte[] targetData = md5.ComputeHash(fromData);
    string byte2String = null; for (int i=0; i<targetData.Length; i++) 
    {
    byte2String += targetData[i].ToString("x");
    } return byte2String;
    }//2
    System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(textBox2.Text.ToString(),"md5");