在C#中怎么用md5的密码md5的密码代码是asp的代码.

解决方案 »

  1.   

    Md5密码是个字符串,16位或32位
    应该是Md5的方法吧?不如重新写个C#的,google或百度找段
      

  2.   

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Security.Cryptography;namespace md5
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine(UserMd5("8"));
                Console.WriteLine(GetMd5Str("8"));
            }
            /**//// <summary>
            /// MD5 16位加密
            /// </summary>
            /// <param name="ConvertString"></param>
            /// <returns></returns>
            public static string GetMd5Str(string ConvertString)
            {
                MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
                string t2 = BitConverter.ToString(md5.ComputeHash(UTF8Encoding.Default.GetBytes(ConvertString)), 4, 8);
                t2 = t2.Replace("-", "");
                return t2;
            }
        }
    }
      

  3.   

    16位的...因为我要兼容以前的ASP代码,,,
      

  4.   

    不是有句:FormsAuthentication.HashPasswordForStoringInConfigFile(this.UserPwd.Text, "MD5")
    但是这个是32位的,有没有16位的,也像这样简单的.
      

  5.   

    http://zzk.cnblogs.com/s?w=md5+C%23&t=
      

  6.   

     FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower().Substring(8, 16);我自己解决了,但是还是谢谢你们.
      

  7.   


        string MD5(string strSource)
        {
            UnicodeEncoding uEncode = new UnicodeEncoding();
            byte[] bs = uEncode.GetBytes(strSource);
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            return Convert.ToBase64String(md5.ComputeHash(bs));
        }