C# md5 hash值求取 添加 system.web的引用

来源:互联网 发布:php 环境 编辑:程序博客网 时间:2024/06/06 13:07
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


namespace md5
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        protected string MD5(string str)
        {
            string test = str;
            System.Security.Cryptography.MD5CryptoServiceProvider md5CSP = new System.Security.Cryptography.MD5CryptoServiceProvider();


            byte[] testEncrypt = System.Text.Encoding.Unicode.GetBytes(test);


            byte[] resultEncrypt = md5CSP.ComputeHash(testEncrypt);


            string testResult = System.Text.Encoding.Unicode.GetString(resultEncrypt);



//这个要在工程里面添加  system.web的引用

            string pwd = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(test, "MD5");
            return pwd.ToLower().Substring(8,16);
        }


        private void button1_Click(object sender, EventArgs e)
        {
            textBox2.Text = MD5(textBox1.Text);
        }
    }
}
0 0
原创粉丝点击