日期:2008-07-31  浏览次数:20463 次

文本的DES加密
为了对称加密的安全,我将密码进行封装,先新建一个用于保存密码的类库cl:
using System;
using System.Text ;

namespace cl
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
public class Class1
{
public Class1()
{


}
public string getiv()
{
string iv="********";//八位
return iv;
}
public string getkey()
{
string key="01160129";//八位
return key;
}

}
}

然后新建ASP.net项目(C#)
在 .ASPx中
using cl;
namespace test//给一个文本产生一个散列值
{
/// <summary>
/// computehash 的摘要说明。
/// </summary>
public class computehash : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.TextBox TextBox3;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.TextBox TextBox4;
protected System.Web.UI.WebControls.Button Button3;
protected System.Web.UI.WebControls.TextBox TextBox5;
protected System.Web.UI.WebControls.Button Button4;
protected System.Web.UI.WebControls.Button Button5;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.TextBox TextBox7;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.TextBox TextBox8;
protected System.Web.UI.WebControls.TextBox TextBox9;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.Button Button6;
protected System.Web.UI.WebControls.Label Label5;
protected System.Web.UI.WebControls.TextBox TextBox2;


private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Button3.Click += new System.EventHandler(this.Button3_Click);
this.Button4.Click += new System.EventHandler(this.Button4_Click);
this.Button5.Click += new System.EventHandler(this.Button5_Click);
this.Button6.Click += new System.EventHandler(this.Button6_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Button1_Click(object sender, System.EventArgs e)
{
byte[] bt=UTF8Encoding.UTF8.GetBytes(TextBox1.Text );//UTF8需要对Text的引用
MD5CryptoServiceProvider objMD5;
objMD5=new MD5CryptoServiceProvider ();
byte[] output=objMD5.ComputeHash (bt);
TextBox2.Text =BitConverter.ToString (output);
}

private void Button2_Click(object sender, System.EventArgs e)
{
byte[] bt=UTF8Encoding.UTF8.GetBytes(TextBox1.Text );//UTF8需要对Text的引用
MD5CryptoServiceProvider objMD5;
objMD5=new MD5CryptoServiceProvider ();
byte[] output=objMD5.ComputeHash (bt);
TextBox4.Text =BitConverter.ToString (output);
}

private void Button3_Click(object sender, System.EventArgs e)
{
Class1 cl=new Class1 ();
string iv1=cl.get