⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webform1.aspx.cs

📁 一个简单的书城代码
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Security.Cryptography;
using System.Text;
using Hugo;

namespace BookShop
{
	/// <summary>
	/// WebForm11 的摘要说明。
	/// </summary>
	public class WebForm11 : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.TextBox TextBox1;
		protected System.Web.UI.WebControls.Button Button1;
		protected System.Web.UI.WebControls.Button Button2;
		protected System.Web.UI.WebControls.Button Button3;
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.TextBox txtKey;
		protected System.Web.UI.WebControls.Button Button4;
		protected System.Web.UI.WebControls.Button Button5;
		protected System.Web.UI.WebControls.Button Button6;
		protected System.Web.UI.WebControls.Button Button7;
		protected System.Web.UI.WebControls.Button Button8;
		protected System.Web.UI.WebControls.TextBox TextBox2;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			//this.TextBox1.Text = Request.ServerVariables["REMOTE_ADDR"];
			//this.TextBox1.Text = Request.UserHostAddress;
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.Button3.Click += new System.EventHandler(this.Button3_Click);
			this.Button2.Click += new System.EventHandler(this.Button2_Click);
			this.Button1.Click += new System.EventHandler(this.Button1_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.Button7.Click += new System.EventHandler(this.Button7_Click);
			this.Button8.Click += new System.EventHandler(this.Button8_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void Button1_Click(object sender, System.EventArgs e)
		{
			//this.TextBox2.Text = this.Encrypt(this.TextBox1.Text,this.txtKey.Text);
			//this.TextBox2.Text = EncryptFile(this.TextBox1.Text,this.txtKey.Text);
			//this.TextBox2.Text = Functions.EncryptCookie(this.TextBox1.Text);
			this.TextBox2.Text = this.Encrypt(this.TextBox1.Text,this.txtKey.Text);
		}

		private void Button2_Click(object sender, System.EventArgs e)
		{
			//this.TextBox1.Text = Hugo.Functions.DecryptCookie(this.TextBox2.Text);
			//this.TextBox1.Text = Functions.DecryptCookie(this.TextBox2.Text);
		}

		private void Button3_Click(object sender, System.EventArgs e)
		{
			//this.Label1.Text = Hugo.Functions.Reverse(this.TextBox1.Text);		
			int i = 1234;
			this.Label1.Text = i.ToString();
		}

		private void Button4_Click(object sender, System.EventArgs e)
		{
//			HttpCookie cookie = new HttpCookie("HugoShopBookLoginTest");
//			string name = "ljy";
//			int id = 5;
//			cookie.Values.Add("UserName",Functions.EncryptCookie(name));
//			cookie.Values.Add("UserId",Functions.EncryptCookie(id.ToString()));
//			string now = DateTime.Now.ToString();
//			cookie.Values.Add("LastVisit",now);						
//			string ip = Request.UserHostAddress;
//			cookie.Values.Add("IP",ip);
//			cookie.Values.Add("VisitTimes","1");
//			//			if(this.chkRemember.Checked)
//			//			{
//			//				cookie.Values.Add("Password",Functions.DecryptCookie(this.tb_Password.Text));
//			//			}
//
//			//Set the sum value of all the cookies to "Value"
//			System.Text.StringBuilder sb = new System.Text.StringBuilder();
//			sb.Append(name);
//			sb.Append(id.ToString());
//			sb.Append(now);
//			sb.Append(ip);
//			int seal = Sum(sb.ToString());
//			cookie.Values.Add("Value",seal.ToString());
//
//			cookie.Expires = DateTime.MaxValue;
//			Response.AppendCookie(cookie);	

		}

		string Encrypt(string sIn,
			string sKey) 
		{
			int i=0;
			byte [] desKey = new Byte [64];
			for(i=0;i<64;i++)
			{
				desKey[i] = (byte)i;
			}
			System.IO.MemoryStream sEncrypted = new System.IO.MemoryStream();
			DESCryptoServiceProvider DES = new DESCryptoServiceProvider();
			//i = DES.LegalKeySizes[0];
			DES.Key = desKey;//ASCIIEncoding.ASCII.GetBytes(sKey);
			DES.IV = desKey;//ASCIIEncoding.ASCII.GetBytes(sKey);
			ICryptoTransform desencrypt = DES.CreateEncryptor();
			CryptoStream cryptostream = new CryptoStream(sEncrypted,
				desencrypt, 
				CryptoStreamMode.Write); 

			byte[] bytearrayinput = new byte[sIn.Length];
			bytearrayinput = ASCIIEncoding.ASCII.GetBytes(sIn);
			cryptostream.Write(bytearrayinput, 0, bytearrayinput.Length);
			

			int j = (int)sEncrypted.Length-1;
			sEncrypted.Seek(0,System.IO.SeekOrigin.Begin);
			for(i=0;i<bytearrayinput.Length;i++)
			{
				bytearrayinput[i] = (byte)0;
			}

			sEncrypted.Read(bytearrayinput,0,j);
			//return (string)bytearrayinput;
//
			cryptostream.Close();
			StringBuilder sb = new StringBuilder();
			foreach(byte a in bytearrayinput)
			{
				sb.Append((char)a);
			}
			return sb.ToString();
		}

//		static void Decrypt(string sIn, 
//			string sOut,
//			string sKey)
//		{
//			DESCryptoServiceProvider DES = new DESCryptoServiceProvider();
//			//A 64 bit key and IV is required for this provider.
//			//Set secret key For DES algorithm.
//			///DES.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
//			//Set initialization vector.
//			///DES.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
//
//			//Create a file stream to read the encrypted file back.
//			FileStream fsread = new FileStream(sIn, 
//				FileMode.Open, 
//				FileAccess.Read);
//			//Create a DES decryptor from the DES instance.
//			ICryptoTransform desdecrypt = DES.CreateDecryptor();
//			//Create crypto stream set to read and do a 
//			//DES decryption transform on incoming bytes.
//			CryptoStream cryptostreamDecr = new CryptoStream(fsread, 
//				desdecrypt,
//				CryptoStreamMode.Read);
//			//Print out the contents of the decrypted file.
//			StreamWriter fsDecrypted = new StreamWriter(sOut);
//			fsDecrypted.Write(new StreamReader(cryptostreamDecr).ReadToEnd());
//			fsDecrypted.Flush();
//			fsDecrypted.Close();
//		}

		//sum
		private int Sum(string str)
		{
			uint sum=0,i=0;
			foreach(char a in str)
			{
				if(i%2==1)//even order number
				{
					sum += a;
					if(sum>65535)//control the max value
					{
						sum &= 0x0ffff;
					}
				}	
				i++;
			}

			return (int)sum;
		}

		private void Button5_Click(object sender, System.EventArgs e)
		{
			this.Label1.Text = Convert.ToString('阿',10);
		}

		private void Button6_Click(object sender, System.EventArgs e)
		{
			this.txtKey.Text = ((char)int.Parse(this.Label1.Text)).ToString();
		}

		private void Button7_Click(object sender, System.EventArgs e)
		{
			//this.TextBox2.Text = Functions.En(this.TextBox1.Text);
		}

		private void Button8_Click(object sender, System.EventArgs e)
		{
			//this.TextBox1.Text = Functions.De(this.TextBox2.Text);
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -