例如 :
我在窗体应用程序中的一个类 Helper.cs类中实现一个字符串的转换
 string pwd="mycipher";额 要把这个 “pwd”转换成MD5码  下面这个方法就不用说了 我试了下 在我的VS2008中无法添加 System.Web.Security;这个引用  也不能添加进项目
String toMD5Pwd=System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(pwd,"MD5").ToLower();
不摘掉各位有什么好的方法?
如果要自己写算法 麻烦注释·写清楚 我是一只小白菜~~~

解决方案 »

  1.   


    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Security.Cryptography;namespace MD5Test
    {
    class Program
    {
    static void Main(string[] args) 
    {
    Program p = new Program();
    Console.Title = "MD5加密  -- 32位加密";
    while(true) {
    Console.Write("请输入要加密的字符(MD5加密):");
    string txt = Console.ReadLine();
    Console.WriteLine(txt + "加密后的结果为(小写):" + p.getmd5(txt, ""));
    Console.WriteLine(txt + "加密后的结果为(大写):" + p.getmd5(txt, "").ToUpper());
    Console.WriteLine();
    }
    }
    public string getmd5(string sdatain, string move)
    {
    MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
    byte[] bytvalue, bythash;
    bytvalue = Encoding.UTF8.GetBytes(move + sdatain);
    bythash = md5.ComputeHash(bytvalue);
    md5.Clear();
    string stemp = "";
    for (int i = 0; i < bythash.Length; i++)
    {
    stemp += bythash[i].ToString("x").PadLeft(2, '0');
    }
    return stemp;
    }
    }
    }
      

  2.   

    Form中引用System.Web;就可以了 
    String toMD5Pwd = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(pwd, "MD5").ToLower();