📄 form1.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(8, 104);
this.textBox1.MaxLength = 8;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(65, 20);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(160, 104);
this.textBox2.MaxLength = 8;
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(65, 20);
this.textBox2.TabIndex = 1;
this.textBox2.Text = "";
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(312, 104);
this.textBox3.MaxLength = 8;
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(65, 20);
this.textBox3.TabIndex = 2;
this.textBox3.Text = "";
//
// groupBox1
//
this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.radioButton3,
this.radioButton2,
this.radioButton1});
this.groupBox1.Location = new System.Drawing.Point(8, 8);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(104, 72);
this.groupBox1.TabIndex = 3;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Key Size";
//
// radioButton3
//
this.radioButton3.Location = new System.Drawing.Point(12, 48);
this.radioButton3.Name = "radioButton3";
this.radioButton3.Size = new System.Drawing.Size(64, 16);
this.radioButton3.TabIndex = 2;
this.radioButton3.Text = "256 bits";
//
// radioButton2
//
this.radioButton2.Location = new System.Drawing.Point(12, 32);
this.radioButton2.Name = "radioButton2";
this.radioButton2.Size = new System.Drawing.Size(64, 16);
this.radioButton2.TabIndex = 1;
this.radioButton2.Text = "192 bits";
//
// radioButton1
//
this.radioButton1.Checked = true;
this.radioButton1.Location = new System.Drawing.Point(12, 16);
this.radioButton1.Name = "radioButton1";
this.radioButton1.Size = new System.Drawing.Size(64, 16);
this.radioButton1.TabIndex = 0;
this.radioButton1.TabStop = true;
this.radioButton1.Text = "128 bits";
//
// button1
//
this.button1.Location = new System.Drawing.Point(80, 104);
this.button1.Name = "button1";
this.button1.TabIndex = 4;
this.button1.Text = "encipher ->";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(232, 104);
this.button2.Name = "button2";
this.button2.TabIndex = 5;
this.button2.Text = "decipher ->";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 88);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(100, 16);
this.label1.TabIndex = 6;
this.label1.Text = "plaintext";
//
// label2
//
this.label2.Location = new System.Drawing.Point(160, 88);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(100, 16);
this.label2.TabIndex = 7;
this.label2.Text = "ciphertext";
//
// label3
//
this.label3.Location = new System.Drawing.Point(312, 88);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(88, 16);
this.label3.TabIndex = 8;
this.label3.Text = "deciphered text";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(400, 149);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.label3,
this.label2,
this.label1,
this.button2,
this.button1,
this.groupBox1,
this.textBox3,
this.textBox2,
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 + -