MD5加密-用做生成数据库访问密码
来源:互联网 发布:中国石油大学北京网络 编辑:程序博客网 时间:2024/05/22 06:30
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Security.Cryptography;
using System.IO;
using System.Text;
namespace WindowsApplication1
...{
/**//// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
...{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
/**//// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
...{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/**//// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
...{
if( disposing )
...{
if (components != null)
...{
components.Dispose();
}
}
base.Dispose( disposing );
}
Windows 窗体设计器生成的代码#region Windows 窗体设计器生成的代码
/**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
...{
this.button1 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(392, 336);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(112, 23);
this.button1.TabIndex = 0;
this.button1.Text = "获取加密后的字符串";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(72, 32);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(640, 128);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "textBox1";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(72, 192);
this.textBox2.Multiline = true;
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(640, 120);
this.textBox2.TabIndex = 2;
this.textBox2.Text = "textBox2";
//
// button2
//
this.button2.Location = new System.Drawing.Point(288, 336);
this.button2.Name = "button2";
this.button2.TabIndex = 3;
this.button2.Text = "生成秘要";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(552, 336);
this.button3.Name = "button3";
this.button3.TabIndex = 4;
this.button3.Text = "解密";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(752, 381);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
/**//// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
...{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
...{
}
private void button1_Click(object sender, System.EventArgs e)
...{
string dsn="Provider=Microsoft.Jet.OLEDB.4.0;Data source={0};";
string dsn2="~/news.DanielCrown817";
StreamReader sr = new StreamReader(@"d:a.txt",UTF8Encoding.UTF8);
string readpublickey = sr.ReadToEnd();
sr.Close();
RSACryptoServiceProvider crypt=new RSACryptoServiceProvider();
UTF8Encoding enc=new UTF8Encoding();
byte[] bytes=enc.GetBytes(dsn);
byte[] bytes2=enc.GetBytes(dsn2);
crypt.FromXmlString( readpublickey );
bytes = crypt.Encrypt( bytes,false );
bytes2=crypt.Encrypt(bytes2,false);
string encryttext=Convert.ToBase64String(bytes);
string encryttext2=Convert.ToBase64String(bytes2);
this.textBox1.Text= encryttext;
this.textBox2.Text=encryttext2;
}
private void button2_Click(object sender, System.EventArgs e)
...{
RSACryptoServiceProvider crypt=new RSACryptoServiceProvider();
string publickey=crypt.ToXmlString(false);//公匙
string privatekey=crypt.ToXmlString(true);//私匙
crypt.Clear();
//写入文本文件中
StreamWriter one=new StreamWriter(@"d:a.txt",true,UTF8Encoding.UTF8);
one.Write(publickey);
StreamWriter two=new StreamWriter(@"d:.txt",true,UTF8Encoding.UTF8);
two.Write(privatekey);
one.Flush();
two.Flush();
one.Close();
two.Close();
MessageBox.Show("成功保存公匙和密匙!");
}
private void button3_Click(object sender, System.EventArgs e)
...{
StreamReader sr = new StreamReader(@"d:.txt",UTF8Encoding.UTF8);
string readprivatekey = sr.ReadToEnd();
sr.Close();
RSACryptoServiceProvider crypt=new RSACryptoServiceProvider();
UTF8Encoding enc=new UTF8Encoding();
byte[] bytes = Convert.FromBase64String(this.textBox1.Text);
byte[] bytes2=Convert.FromBase64String(this.textBox2.Text);
crypt.FromXmlString ( readprivatekey ) ;
byte[] decryptbyte = crypt.Decrypt( bytes,false );
byte[] decryptbyte2=crypt.Decrypt(bytes2,false);
string d=enc.GetString(decryptbyte);
string d2=enc.GetString(decryptbyte2);
this.textBox1.Text=d;
this.textBox2.Text=d2;
}
}
}
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Security.Cryptography;
using System.IO;
using System.Text;
namespace WindowsApplication1
...{
/**//// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
...{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
/**//// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
...{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/**//// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
...{
if( disposing )
...{
if (components != null)
...{
components.Dispose();
}
}
base.Dispose( disposing );
}
Windows 窗体设计器生成的代码#region Windows 窗体设计器生成的代码
/**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
...{
this.button1 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(392, 336);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(112, 23);
this.button1.TabIndex = 0;
this.button1.Text = "获取加密后的字符串";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(72, 32);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(640, 128);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "textBox1";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(72, 192);
this.textBox2.Multiline = true;
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(640, 120);
this.textBox2.TabIndex = 2;
this.textBox2.Text = "textBox2";
//
// button2
//
this.button2.Location = new System.Drawing.Point(288, 336);
this.button2.Name = "button2";
this.button2.TabIndex = 3;
this.button2.Text = "生成秘要";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(552, 336);
this.button3.Name = "button3";
this.button3.TabIndex = 4;
this.button3.Text = "解密";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(752, 381);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
/**//// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
...{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
...{
}
private void button1_Click(object sender, System.EventArgs e)
...{
string dsn="Provider=Microsoft.Jet.OLEDB.4.0;Data source={0};";
string dsn2="~/news.DanielCrown817";
StreamReader sr = new StreamReader(@"d:a.txt",UTF8Encoding.UTF8);
string readpublickey = sr.ReadToEnd();
sr.Close();
RSACryptoServiceProvider crypt=new RSACryptoServiceProvider();
UTF8Encoding enc=new UTF8Encoding();
byte[] bytes=enc.GetBytes(dsn);
byte[] bytes2=enc.GetBytes(dsn2);
crypt.FromXmlString( readpublickey );
bytes = crypt.Encrypt( bytes,false );
bytes2=crypt.Encrypt(bytes2,false);
string encryttext=Convert.ToBase64String(bytes);
string encryttext2=Convert.ToBase64String(bytes2);
this.textBox1.Text= encryttext;
this.textBox2.Text=encryttext2;
}
private void button2_Click(object sender, System.EventArgs e)
...{
RSACryptoServiceProvider crypt=new RSACryptoServiceProvider();
string publickey=crypt.ToXmlString(false);//公匙
string privatekey=crypt.ToXmlString(true);//私匙
crypt.Clear();
//写入文本文件中
StreamWriter one=new StreamWriter(@"d:a.txt",true,UTF8Encoding.UTF8);
one.Write(publickey);
StreamWriter two=new StreamWriter(@"d:.txt",true,UTF8Encoding.UTF8);
two.Write(privatekey);
one.Flush();
two.Flush();
one.Close();
two.Close();
MessageBox.Show("成功保存公匙和密匙!");
}
private void button3_Click(object sender, System.EventArgs e)
...{
StreamReader sr = new StreamReader(@"d:.txt",UTF8Encoding.UTF8);
string readprivatekey = sr.ReadToEnd();
sr.Close();
RSACryptoServiceProvider crypt=new RSACryptoServiceProvider();
UTF8Encoding enc=new UTF8Encoding();
byte[] bytes = Convert.FromBase64String(this.textBox1.Text);
byte[] bytes2=Convert.FromBase64String(this.textBox2.Text);
crypt.FromXmlString ( readprivatekey ) ;
byte[] decryptbyte = crypt.Decrypt( bytes,false );
byte[] decryptbyte2=crypt.Decrypt(bytes2,false);
string d=enc.GetString(decryptbyte);
string d2=enc.GetString(decryptbyte2);
this.textBox1.Text=d;
this.textBox2.Text=d2;
}
}
}
- MD5加密-用做生成数据库访问密码
- 生成MD5码----密码加密
- 密码加密生成函数Md5
- 利用MD5加密数据库中的密码
- 利用MD5加密数据库中的密码
- 利用MD5加密数据库中的密码
- 数据库密码被MD5加密了
- 查询数据库之前把密码md5加密
- JAVA 数据库密码加密(MD5)
- MD5应用于数据库中密码加密
- 如何配置数据库密码加密访问数据库
- linux下 生成 resin-admin的 md5加密的密码
- MD5加密密码!
- MD5 密码加密
- MD5加密密码
- java 密码MD5加密
- C#MD5密码加密
- 密码加密MD5
- 中国家长的身上藏着十把刀
- Javascript 刷新框架及页面的方法总集
- 数据库访问类
- .net C# 动画技术大全,百叶窗,卷动,积木效果,世界之窗,双缓冲技术
- 详细解说 STL 排序(Sort)
- MD5加密-用做生成数据库访问密码
- MVC在.net C#上的应用
- CSDN Blog V3.0.0.2升级公告
- MVC模式在.NET框架中的应用与实现
- 踏雪有痕-const常量
- 如何使用第三方COM组件
- mysql使用rand随机查询记录效率测试
- 赤壁之战---恶搞版
- 关于渗透的一点入手方面