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

📄 form1.cs

📁 C#编写
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

using AesLib;
using System.Text;

namespace AesDemoWinApp
{
	public class Form1 : System.Windows.Forms.Form
	{
    private System.Windows.Forms.TextBox textBox1;
    private System.Windows.Forms.TextBox textBox2;
    private System.Windows.Forms.TextBox textBox3;
    private System.Windows.Forms.GroupBox groupBox1;
    private System.Windows.Forms.RadioButton radioButton1;
    private System.Windows.Forms.RadioButton radioButton2;
    private System.Windows.Forms.RadioButton radioButton3;
    private System.Windows.Forms.Button button1;
    private System.Windows.Forms.Button button2;
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.Label label2;
    private System.Windows.Forms.Label label3;
		
		private System.ComponentModel.Container components = null;

    private Aes.KeySize keysize;

		public Form1()
		{
			InitializeComponent();
		}

		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.textBox2 = new System.Windows.Forms.TextBox();
			this.textBox3 = new System.Windows.Forms.TextBox();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.radioButton3 = new System.Windows.Forms.RadioButton();
			this.radioButton2 = new System.Windows.Forms.RadioButton();
			this.radioButton1 = new System.Windows.Forms.RadioButton();
			this.button1 = new System.Windows.Forms.Button();
			this.button2 = new System.Windows.Forms.Button();
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.groupBox1.SuspendLayout();
			this.SuspendLayout();
			// 
			// textBox1
			// 
			this.textBox1.Location = new System.Drawing.Point(10, 112);
			this.textBox1.MaxLength = 8;
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(78, 21);
			this.textBox1.TabIndex = 0;
			this.textBox1.Text = "";
			// 
			// textBox2
			// 
			this.textBox2.Location = new System.Drawing.Point(192, 112);
			this.textBox2.MaxLength = 8;
			this.textBox2.Name = "textBox2";
			this.textBox2.Size = new System.Drawing.Size(78, 21);
			this.textBox2.TabIndex = 1;
			this.textBox2.Text = "";
			// 
			// textBox3
			// 
			this.textBox3.Location = new System.Drawing.Point(374, 112);
			this.textBox3.MaxLength = 8;
			this.textBox3.Name = "textBox3";
			this.textBox3.Size = new System.Drawing.Size(78, 21);
			this.textBox3.TabIndex = 2;
			this.textBox3.Text = "";
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.radioButton3);
			this.groupBox1.Controls.Add(this.radioButton2);
			this.groupBox1.Controls.Add(this.radioButton1);
			this.groupBox1.Location = new System.Drawing.Point(10, 9);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(124, 77);
			this.groupBox1.TabIndex = 3;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Key Size";
			// 
			// radioButton3
			// 
			this.radioButton3.Location = new System.Drawing.Point(14, 52);
			this.radioButton3.Name = "radioButton3";
			this.radioButton3.Size = new System.Drawing.Size(77, 17);
			this.radioButton3.TabIndex = 2;
			this.radioButton3.Text = "256 bits";
			// 
			// radioButton2
			// 
			this.radioButton2.Location = new System.Drawing.Point(14, 34);
			this.radioButton2.Name = "radioButton2";
			this.radioButton2.Size = new System.Drawing.Size(77, 18);
			this.radioButton2.TabIndex = 1;
			this.radioButton2.Text = "192 bits";
			// 
			// radioButton1
			// 
			this.radioButton1.Checked = true;
			this.radioButton1.Location = new System.Drawing.Point(14, 17);
			this.radioButton1.Name = "radioButton1";
			this.radioButton1.Size = new System.Drawing.Size(77, 17);
			this.radioButton1.TabIndex = 0;
			this.radioButton1.TabStop = true;
			this.radioButton1.Text = "128 bits";
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(96, 112);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(90, 25);
			this.button1.TabIndex = 4;
			this.button1.Text = "译成密文 ->";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(278, 112);
			this.button2.Name = "button2";
			this.button2.Size = new System.Drawing.Size(90, 25);
			this.button2.TabIndex = 5;
			this.button2.Text = "译成明文 ->";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(10, 95);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(120, 17);
			this.label1.TabIndex = 6;
			this.label1.Text = "加密文本";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(192, 95);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(120, 17);
			this.label2.TabIndex = 7;
			this.label2.Text = "密文";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(374, 95);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(106, 17);
			this.label3.TabIndex = 8;
			this.label3.Text = "还原文本";
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(480, 160);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.textBox3);
			this.Controls.Add(this.textBox2);
			this.Controls.Add(this.textBox1);
			this.Name = "Form1";
			this.Text = "Advanced Encryption Standard Demo in .NET";
			this.groupBox1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

    private void button1_Click(object sender, System.EventArgs e)
    {
      if (radioButton1.Checked)
        keysize = Aes.KeySize.Bits128;
      else if (radioButton2.Checked)
        keysize = Aes.KeySize.Bits192;
      else
        keysize = Aes.KeySize.Bits256;

      byte[] plainText = new byte[16];
      byte[] cipherText = new byte[16];  
      
      plainText = Encoding.Unicode.GetBytes(textBox1.Text.PadRight(8,' '));
      AesLib.Aes a = new Aes(keysize, new byte[16]);
      a.Cipher(plainText, cipherText);
      textBox2.Text = Encoding.Unicode.GetString(cipherText);
    }  // button1_Click()

    private void button2_Click(object sender, System.EventArgs e)
    {
      if (radioButton1.Checked)
        keysize = Aes.KeySize.Bits128;
      else if (radioButton2.Checked)
        keysize = Aes.KeySize.Bits192;
      else
        keysize = Aes.KeySize.Bits256;

      byte[] cipherText = new byte[16];
      byte[] decipheredText = new byte[16];

      cipherText = Encoding.Unicode.GetBytes(textBox2.Text);
      AesLib.Aes a = new Aes(keysize, new byte[16]);
      a.InvCipher(cipherText, decipheredText);
      textBox3.Text = Encoding.Unicode.GetString(decipheredText);;
    }  // button2_Click()

	}  // class Form1
}  // ns AesDemoWinApp

⌨️ 快捷键说明

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