现在的位置: 首页 > 综合 > 正文

MD5 加密

2013年06月22日 ⁄ 综合 ⁄ 共 1580字 ⁄ 字号 评论关闭

  /// <summary>
        /// 返回字符串MD5加密
        /// </summary>
        /// <param name="strPlain">要转换字符串</param>
        /// <returns></returns>
        internal string GetMD5(string strPlain)
        {
            System.Security.Cryptography.MD5 md = new System.Security.Cryptography.MD5CryptoServiceProvider();
            byte[] inArray1 = System.Text.UnicodeEncoding.Unicode.GetBytes(strPlain);
            byte[] inArray2 = md.ComputeHash(inArray1);

            string strHex = "";
            foreach (byte b in inArray2)
            {
                strHex += string.Format("{0:x2}", b);
            }
            return strHex;
        }

 private void button1_Click(object sender, EventArgs e)
        {
            double k = 10000000000;
            string l = k.ToString("n");
            string f = "1986-01-11";
            MessageBox.Show(f.Substring(0, 4) + "年" + f.Substring(5, 2) + "月" + f.Substring(8, 2) + "日");
            MessageBox.Show(k.ToString("f2") + k.ToString("n"));
            MessageBox.Show(k.ToString("n"));
            MessageBox.Show(l.Replace(",",null));
        }
        /// <summary>
        /// 返回字符串MD5加密
        /// </summary>
        /// <param name="strPlain">要转换字符串</param>
        /// <returns></returns>
        internal string GetMD5(string strPlain)
        {
            System.Security.Cryptography.MD5 md = new System.Security.Cryptography.MD5CryptoServiceProvider();
            byte[] inArray1 = System.Text.UnicodeEncoding.Unicode.GetBytes(strPlain);
            byte[] inArray2 = md.ComputeHash(inArray1);
            string strHex = "";
            foreach (byte b in inArray2)
            {
                strHex += string.Format("{0:x2}", b);
            }
            return strHex;
        }

抱歉!评论已关闭.