Text DES encryption for symmetrical encryption, I encapsulate passwords, first create a library CL: use system; use system; usingspace cl {///
} 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 {///
#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);} ///
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));}}}