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

📄 form1.cs

📁 C#做的加密解密的东西
💻 CS
📖 第 1 页 / 共 4 页
字号:
			this.richText5.TabIndex = 25;
			this.richText5.Text = "";
			// 
			// textPub
			// 
			this.textPub.Location = new System.Drawing.Point(8, 192);
			this.textPub.Multiline = true;
			this.textPub.Name = "textPub";
			this.textPub.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
			this.textPub.Size = new System.Drawing.Size(200, 32);
			this.textPub.TabIndex = 24;
			this.textPub.Text = "";
			// 
			// textPri
			// 
			this.textPri.Location = new System.Drawing.Point(8, 224);
			this.textPri.Multiline = true;
			this.textPri.Name = "textPri";
			this.textPri.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
			this.textPri.Size = new System.Drawing.Size(200, 32);
			this.textPri.TabIndex = 23;
			this.textPri.Text = "";
			// 
			// button21
			// 
			this.button21.Location = new System.Drawing.Point(8, 280);
			this.button21.Name = "button21";
			this.button21.Size = new System.Drawing.Size(72, 23);
			this.button21.TabIndex = 22;
			this.button21.Text = "开始加密";
			this.button21.Click += new System.EventHandler(this.button21_Click);
			// 
			// button22
			// 
			this.button22.Location = new System.Drawing.Point(80, 280);
			this.button22.Name = "button22";
			this.button22.Size = new System.Drawing.Size(64, 23);
			this.button22.TabIndex = 21;
			this.button22.Text = "开始解密";
			this.button22.Click += new System.EventHandler(this.button22_Click);
			// 
			// button23
			// 
			this.button23.Location = new System.Drawing.Point(8, 256);
			this.button23.Name = "button23";
			this.button23.Size = new System.Drawing.Size(72, 23);
			this.button23.TabIndex = 20;
			this.button23.Text = "读取公钥";
			this.button23.Click += new System.EventHandler(this.button23_Click);
			// 
			// button24
			// 
			this.button24.Location = new System.Drawing.Point(80, 256);
			this.button24.Name = "button24";
			this.button24.Size = new System.Drawing.Size(64, 23);
			this.button24.TabIndex = 19;
			this.button24.Text = "读取私钥";
			this.button24.Click += new System.EventHandler(this.button24_Click);
			// 
			// button25
			// 
			this.button25.Location = new System.Drawing.Point(144, 256);
			this.button25.Name = "button25";
			this.button25.Size = new System.Drawing.Size(64, 48);
			this.button25.TabIndex = 18;
			this.button25.Text = "清空文本";
			this.button25.Click += new System.EventHandler(this.button25_Click);
			// 
			// richText4
			// 
			this.richText4.Location = new System.Drawing.Point(8, 72);
			this.richText4.Name = "richText4";
			this.richText4.Size = new System.Drawing.Size(200, 32);
			this.richText4.TabIndex = 17;
			this.richText4.Text = "";
			// 
			// textBox2
			// 
			this.textBox2.Location = new System.Drawing.Point(8, 24);
			this.textBox2.Name = "textBox2";
			this.textBox2.Size = new System.Drawing.Size(128, 21);
			this.textBox2.TabIndex = 16;
			this.textBox2.Text = "";
			// 
			// button19
			// 
			this.button19.Location = new System.Drawing.Point(152, 24);
			this.button19.Name = "button19";
			this.button19.Size = new System.Drawing.Size(40, 23);
			this.button19.TabIndex = 15;
			this.button19.Text = "打开";
			this.button19.Click += new System.EventHandler(this.button19_Click);
			// 
			// textBox3
			// 
			this.textBox3.Location = new System.Drawing.Point(8, 48);
			this.textBox3.Name = "textBox3";
			this.textBox3.Size = new System.Drawing.Size(128, 21);
			this.textBox3.TabIndex = 14;
			this.textBox3.Text = "";
			// 
			// button20
			// 
			this.button20.Location = new System.Drawing.Point(152, 48);
			this.button20.Name = "button20";
			this.button20.Size = new System.Drawing.Size(40, 23);
			this.button20.TabIndex = 13;
			this.button20.Text = "保存";
			this.button20.Click += new System.EventHandler(this.button20_Click);
			// 
			// groupBox3
			// 
			this.groupBox3.Controls.Add(this.button15);
			this.groupBox3.Controls.Add(this.button16);
			this.groupBox3.Controls.Add(this.button17);
			this.groupBox3.Controls.Add(this.button18);
			this.groupBox3.Controls.Add(this.label11);
			this.groupBox3.Controls.Add(this.textBox1);
			this.groupBox3.Controls.Add(this.richText3);
			this.groupBox3.Controls.Add(this.label12);
			this.groupBox3.Controls.Add(this.richText2);
			this.groupBox3.Controls.Add(this.label13);
			this.groupBox3.Controls.Add(this.richText1);
			this.groupBox3.Controls.Add(this.button11);
			this.groupBox3.Controls.Add(this.button12);
			this.groupBox3.Controls.Add(this.button13);
			this.groupBox3.Controls.Add(this.button14);
			this.groupBox3.Location = new System.Drawing.Point(8, 8);
			this.groupBox3.Name = "groupBox3";
			this.groupBox3.Size = new System.Drawing.Size(216, 312);
			this.groupBox3.TabIndex = 0;
			this.groupBox3.TabStop = false;
			this.groupBox3.Text = "字符串加密";
			// 
			// button15
			// 
			this.button15.Location = new System.Drawing.Point(112, 280);
			this.button15.Name = "button15";
			this.button15.Size = new System.Drawing.Size(96, 24);
			this.button15.TabIndex = 19;
			this.button15.Text = "私钥解密";
			this.button15.Click += new System.EventHandler(this.button15_Click);
			// 
			// button16
			// 
			this.button16.Location = new System.Drawing.Point(16, 280);
			this.button16.Name = "button16";
			this.button16.Size = new System.Drawing.Size(96, 24);
			this.button16.TabIndex = 18;
			this.button16.Text = "公钥加密";
			this.button16.Click += new System.EventHandler(this.button16_Click);
			// 
			// button17
			// 
			this.button17.Location = new System.Drawing.Point(16, 256);
			this.button17.Name = "button17";
			this.button17.Size = new System.Drawing.Size(96, 24);
			this.button17.TabIndex = 17;
			this.button17.Text = "读取公钥";
			this.button17.Click += new System.EventHandler(this.button17_Click);
			// 
			// button18
			// 
			this.button18.Location = new System.Drawing.Point(112, 256);
			this.button18.Name = "button18";
			this.button18.Size = new System.Drawing.Size(96, 24);
			this.button18.TabIndex = 16;
			this.button18.Text = "读取私钥";
			this.button18.Click += new System.EventHandler(this.button18_Click);
			// 
			// label11
			// 
			this.label11.Location = new System.Drawing.Point(8, 136);
			this.label11.Name = "label11";
			this.label11.Size = new System.Drawing.Size(56, 16);
			this.label11.TabIndex = 15;
			this.label11.Text = "加密文字";
			// 
			// textBox1
			// 
			this.textBox1.Location = new System.Drawing.Point(64, 128);
			this.textBox1.Multiline = true;
			this.textBox1.Name = "textBox1";
			this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
			this.textBox1.Size = new System.Drawing.Size(144, 40);
			this.textBox1.TabIndex = 14;
			this.textBox1.Text = "";
			// 
			// richText3
			// 
			this.richText3.Location = new System.Drawing.Point(64, 208);
			this.richText3.Name = "richText3";
			this.richText3.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.None;
			this.richText3.Size = new System.Drawing.Size(144, 40);
			this.richText3.TabIndex = 13;
			this.richText3.Text = "";
			// 
			// label12
			// 
			this.label12.Location = new System.Drawing.Point(8, 176);
			this.label12.Name = "label12";
			this.label12.Size = new System.Drawing.Size(56, 16);
			this.label12.TabIndex = 12;
			this.label12.Text = "加密结果";
			// 
			// richText2
			// 
			this.richText2.Location = new System.Drawing.Point(64, 168);
			this.richText2.Name = "richText2";
			this.richText2.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.None;
			this.richText2.Size = new System.Drawing.Size(144, 40);
			this.richText2.TabIndex = 11;
			this.richText2.Text = "";
			// 
			// label13
			// 
			this.label13.Location = new System.Drawing.Point(8, 216);
			this.label13.Name = "label13";
			this.label13.Size = new System.Drawing.Size(56, 16);
			this.label13.TabIndex = 10;
			this.label13.Text = "解密结果";
			// 
			// richText1
			// 
			this.richText1.Location = new System.Drawing.Point(8, 17);
			this.richText1.Name = "richText1";
			this.richText1.Size = new System.Drawing.Size(200, 56);
			this.richText1.TabIndex = 8;
			this.richText1.Text = "";
			// 
			// button11
			// 
			this.button11.Enabled = false;
			this.button11.Location = new System.Drawing.Point(8, 96);
			this.button11.Name = "button11";
			this.button11.Size = new System.Drawing.Size(192, 23);
			this.button11.TabIndex = 7;
			this.button11.Text = "写入文件";
			// 
			// button12
			// 
			this.button12.Location = new System.Drawing.Point(136, 72);
			this.button12.Name = "button12";
			this.button12.Size = new System.Drawing.Size(64, 23);
			this.button12.TabIndex = 6;
			this.button12.Text = "保存私钥";
			this.button12.Click += new System.EventHandler(this.button12_Click);
			// 
			// button13
			// 
			this.button13.Location = new System.Drawing.Point(72, 72);
			this.button13.Name = "button13";
			this.button13.Size = new System.Drawing.Size(64, 23);
			this.button13.TabIndex = 5;
			this.button13.Text = "保存公钥";
			this.button13.Click += new System.EventHandler(this.button13_Click);
			// 
			// button14
			// 
			this.button14.Location = new System.Drawing.Point(8, 72);
			this.button14.Name = "button14";
			this.button14.Size = new System.Drawing.Size(64, 23);
			this.button14.TabIndex = 4;
			this.button14.Text = "产生钥匙";
			this.button14.Click += new System.EventHandler(this.button14_Click);
			// 
			// label15
			// 
			this.label15.Location = new System.Drawing.Point(8, 232);
			this.label15.Name = "label15";
			this.label15.Size = new System.Drawing.Size(72, 16);
			this.label15.TabIndex = 25;
			this.label15.Text = "文本-数据库";
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(456, 373);
			this.Controls.Add(this.tabControl1);
			this.Name = "Form1";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Form1";
			this.tabControl1.ResumeLayout(false);
			this.tabPage1.ResumeLayout(false);
			this.groupBox1.ResumeLayout(false);
			this.tabPage2.ResumeLayout(false);
			this.groupBox2.ResumeLayout(false);
			this.tabPage3.ResumeLayout(false);
			this.groupBox4.ResumeLayout(false);
			this.groupBox3.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		private SymmetricAlgorithm SetEnc()
		{
			if(optDES.Checked)
				return new DESCryptoServiceProvider();
			else
				return new TripleDESCryptoServiceProvider();
		}

		private string EncryptString(string Value)
		{
			ICryptoTransform ct;
			MemoryStream ms;
			CryptoStream cs;
			byte[] byt;
			ct=mCSP.CreateEncryptor(mCSP.Key,mCSP.IV);
			byt=Encoding.UTF8.GetBytes(Value);
			ms=new MemoryStream();
			cs=new CryptoStream(ms,ct,CryptoStreamMode.Write);
			cs.Write(byt, 0, byt.Length);
			cs.FlushFinalBlock();
			//cs.Close();
			return Convert.ToBase64String(ms.ToArray());
			//return Encoding.UTF8.GetString(ms.ToArray());

		}

		private string DecryptString(string Value)
		{
			ICryptoTransform ct;
			MemoryStream ms;
			CryptoStream cs;
			byte[] byt;
			ct = mCSP.CreateDecryptor(mCSP.Key, mCSP.IV);
			byt = Convert.FromBase64String(Value);
			ms = new MemoryStream();
			cs = new CryptoStream(ms, ct, CryptoStreamMode.Write);
			cs.Write(byt, 0, byt.Length);
			cs.FlushFinalBlock();
			//cs.Close();
			return Encoding.UTF8.GetString(ms.ToArray());
			//return Convert.ToBase64String(ms.ToArray());
		}

		private void md5txt()
		{
			StreamReader objReader = new StreamReader("md52.txt");
			string sLine="";
			sLine = objReader.ReadLine();
			textSee.Text=sLine.ToString();
			objReader.Close();			
		}

		private void button7_Click(object sender, System.EventArgs e)
		{
			byte[] Hashbyte;
			FileStream objFile=File.OpenRead("md5.txt");			
			HashAlgorithm MD5=HashAlgorithm.Create("MD5");
			Hashbyte=MD5.ComputeHash(objFile);
			objFile.Close();
			foreach(byte b in Hashbyte)
			textHax.Text=b.ToString()+"";
		}

		private void button11_Click(object sender, System.EventArgs e)
		{
			text11.Text=textName.Text+textPass.Text;
		}

		private void button5_Click_1(object sender, System.EventArgs e)
		{
			mCSP = SetEnc();
			mCSP.GenerateKey();
			textKey.Text=Convert.ToBase64String(mCSP.Key);
		}

		private void button2_Click_1(object sender, System.EventArgs e)
		{
			mCSP.GenerateIV();
			textIv.Text=Convert.ToBase64String(mCSP.IV);
		}

		private void button3_Click_1(object sender, System.EventArgs e)
		{
			textEncrypted.Text=EncryptString(textOriginal.Text);
		}

		private void button4_Click_1(object sender, System.EventArgs e)
		{
			text11.Text=DecryptString(textEncrypted.Text);
		}

		private void button1_Click_1(object sender, System.EventArgs e)
		{
			string readerMd5,reGx,reGx2;
			md5txt();
			readerMd5=textSee.Text;			
			byte[] bt=UTF8Encoding.UTF8.GetBytes(readerMd5.ToString());
			MD5CryptoServiceProvider objMD5;
			objMD5=new MD5CryptoServiceProvider();
			byte[] output=objMD5.ComputeHash (bt);
			//objFile.Close();
			 reGx=BitConverter.ToString (output);

⌨️ 快捷键说明

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