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);
return pwd.ToLower().Substring(8,16);
}
private void button1_Click(object sender, EventArgs e)
{
textBox2.Text = MD5(textBox1.Text);
}
}
}
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);
}
}
}