C# MD5加密例子

using System.Security.Cryptography;
        // <summary>
        /// MD5 32位加密
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        private string UserMd5(string str)
        {

            string cl = str;
            MD5 md5 = new MD5CryptoServiceProvider();
            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(str);
            bytes = md5.ComputeHash(bytes);
            md5.Clear();

            string ret = "";
            for (int i = 0; i < bytes.Length; i++)
            {
                ret += Convert.ToString(bytes[i], 16).PadLeft(2, '0');
            }

            return ret.PadLeft(32, '0');
        }
例子

 

posted @ 2015-09-09 16:32  飞行在午夜  阅读(95)  评论(0编辑  收藏  举报