.net 2.0 使用MD5加密字符

using System.Security.Cryptography;

       /// <summary>
        /// 加密字符串,返回密文
        /// </summary>
        /// <param name="password"></param>
        /// <returns></returns>
        public static string EncryptString(string password)
        {
            string strReturn = "";
            byte[] data = System.Text.Encoding.Unicode.GetBytes(password);
            MD5 md5 = new MD5CryptoServiceProvider();

            byte[] result = md5.ComputeHash(data);

            for (int j = 0; j < result.Length; j++)
            {
                strReturn += result[j].ToString("X").PadLeft(2,'0');
            }

            return strReturn;
        }

posted on 2006-10-26 22:53  bike  阅读(445)  评论(0编辑  收藏  举报

导航