Text DES Encrypted MD5 Ratings DSA Digital Signature

xiaoxiao2021-03-06  114

Text DES encryption for symmetrical encryption, I encapsulate passwords, first create a library CL: use system; use system; usingspace cl {///

/// class1 Abstract. /// public class class1 {public class1 () {

} Public string getiv () {string IV = "*********"; // eight Return IV;} public string getKey () {string key = "01160129"; // eight Return Key;}

}} Then create the ASP.NET item (C #) in .. Using Cl; Namespace Test // gives a section a hash value {///

/// computehash's summary description. /// 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 button; protected system.web.ui.Webc Ontrols.label label5; protected system.web.ui.webcontrols.textbox textbox2; private void page_load (object sender, system.eventargs e) {// Place user code here to initialize page}

#Region Web Form Designer Generated Code Override Protected Void OnNit (Eventargs E) {// // Codegen: This call is required for the ASP.NET Web Form Designer. // InitializeComponent (); base.onit (e);} ///

/// Designer Supports the required method - Do not use the code editor to modify the // / this method. /// 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 need to refer to Text of 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 need to refer to Text of 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); // defines the encryption target DESCryptoServiceProvider objdes; objdes = new DESCryptoServiceProvider (); // set the encryption target value objdes.IV = iv; objdes.Key = key; // create an encrypted object ICryptoTransform objEncryptor; objEncryptor = objdes.CreateEncryptor (objdes.Key, objdes.IV) // Prepare to write encrypted text into secret.txt FileStream Objfs; Objfs = New FileStream (Mappath ("Secret.txt"), FileMode.create, FileAccess.write; // 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 [ ] SO urce = UTF8Encoding.UTF8 .GetBytes (TextBox1.Text); // defines the encryption target DESCryptoServiceProvider objdes; objdes = new DESCryptoServiceProvider (); // set the encryption target value objdes.IV = iv; objdes.Key = key; // create encrypted object ICryptoTransform objEncryptor; objEncryptor = objdes.CreateEncryptor (objdes.Key, objdes.IV); // write memory 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); // disclosed keys TextBox8.Text = objdsa. Toxmlstring (false); // Private secret key TextBox9.text = objdsa.toxmlstring (true); // Digital signature textbox7.text = bitconverter.tostring (Objdsa.SignData (Source));}}}

转载请注明原文地址:https://www.9cbs.com/read-103225.html

New Post(0)