日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

文本的DES加密 MD5散列值 DSA的数字签名

發布時間:2023/11/27 生活经验 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 文本的DES加密 MD5散列值 DSA的数字签名 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

作者:未知

文本的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.getiv ();
???string key1=cl.getkey ();

???byte[] iv=UTF8Encoding.UTF8 .GetBytes (iv1);
???byte[] key=UTF8Encoding.UTF8 .GetBytes (key1);
???byte[] source=UTF8Encoding.UTF8 .GetBytes (TextBox1.Text );
???//定義加密對象
???DESCryptoServiceProvider objdes;
??????????? objdes=new DESCryptoServiceProvider ();
???//設置加密對象值
???objdes.IV =iv;
???objdes.Key =key;
???//創建加密器對象
???ICryptoTransform objEncryptor;
???objEncryptor=objdes.CreateEncryptor (objdes.Key ,objdes.IV );
??????????? //準備將加密的文本寫入secret.txt中
???FileStream objfs;
???objfs=new FileStream (MapPath("secret.txt"),FileMode.Create ,FileAccess.Write );
??????????? //寫入
???CryptoStream cryptostream;
???cryptostream=new CryptoStream (objfs,objEncryptor,CryptoStreamMode.Write );
???cryptostream.Write (source,0,source.Length );
???cryptostream.Close ();
??}

??private void Button4_Click(object sender, System.EventArgs e)
??{
???Class1 cl=new Class1 ();
???string iv1=cl.getiv ();
???string key1=cl.getkey ();
?
???byte[] iv=UTF8Encoding.UTF8 .GetBytes (iv1);
???byte[] key=UTF8Encoding.UTF8 .GetBytes (key1);
???byte[] source=UTF8Encoding.UTF8 .GetBytes (TextBox1.Text );
???//定義加密對象
???DESCryptoServiceProvider objdes;
???objdes=new DESCryptoServiceProvider ();
???//設置加密對象值
???objdes.IV =iv;
???objdes.Key =key;
???//創建加密器對象
???ICryptoTransform objEncryptor;
???objEncryptor=objdes.CreateEncryptor (objdes.Key ,objdes.IV );
???//寫到內存
???MemoryStream ms=new MemoryStream ();
???CryptoStream cs=new CryptoStream (ms,objEncryptor,CryptoStreamMode.Write );
???cs.Write (source,0,source.Length );
???cs.FlushFinalBlock ();
???ms.Close ();
???TextBox5.Text =BitConverter.ToString (ms.ToArray ());

??}

??private void Button5_Click(object sender, System.EventArgs e)
??{
???DSACryptoServiceProvider objdsa;
???objdsa=new DSACryptoServiceProvider ();
??????????? byte[] source=UTF8Encoding.UTF8 .GetBytes (TextBox1.Text );
???//公開秘鑰
???TextBox8.Text =objdsa.ToXmlString (false);
???//私有秘鑰
???TextBox9.Text =objdsa.ToXmlString (true);
???//數字簽名
???TextBox7.Text =BitConverter.ToString (objdsa.SignData (source));
??}

??}
}

總結

以上是生活随笔為你收集整理的文本的DES加密 MD5散列值 DSA的数字签名的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。