using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Cryptography;
namespace Cryptography_Demo
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class frmmain : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox groupBox4;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox txtprk;
private System.Windows.Forms.TextBox txtpk;
private System.Windows.Forms.TextBox txtcipher;
private System.Windows.Forms.TextBox txtplain;
private System.Windows.Forms.TextBox txtiv;
private System.Windows.Forms.TextBox txtsk;
private System.Windows.Forms.Button btngs;
private System.Windows.Forms.Button btnds;
private System.Windows.Forms.Button btnes;
private System.Windows.Forms.Button btnga;
private System.Windows.Forms.Button btnda;
private System.Windows.Forms.Button btnea;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public frmmain()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
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.groupBox4 = new System.Windows.Forms.GroupBox();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.txtiv = new System.Windows.Forms.TextBox();
this.txtsk = new System.Windows.Forms.TextBox();
this.btngs = new System.Windows.Forms.Button();
this.btnds = new System.Windows.Forms.Button();
this.btnes = new System.Windows.Forms.Button();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.txtcipher = new System.Windows.Forms.TextBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.txtplain = new System.Windows.Forms.TextBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.txtprk = new System.Windows.Forms.TextBox();
this.txtpk = new System.Windows.Forms.TextBox();
this.btnga = new System.Windows.Forms.Button();
this.btnda = new System.Windows.Forms.Button();
this.btnea = new System.Windows.Forms.Button();
this.groupBox4.SuspendLayout();
this.groupBox3.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// groupBox4
//
this.groupBox4.Controls.Add(this.label3);
this.groupBox4.Controls.Add(this.label4);
this.groupBox4.Controls.Add(this.txtiv);
this.groupBox4.Controls.Add(this.txtsk);
this.groupBox4.Controls.Add(this.btngs);
this.groupBox4.Controls.Add(this.btnds);
this.groupBox4.Controls.Add(this.btnes);
this.groupBox4.Location = new System.Drawing.Point(52, 350);
this.groupBox4.Name = "groupBox4";
this.groupBox4.Size = new System.Drawing.Size(352, 152);
this.groupBox4.TabIndex = 18;
this.groupBox4.TabStop = false;
this.groupBox4.Text = "Asymetric Cryptography";
//
// label3
//
this.label3.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label3.Location = new System.Drawing.Point(107, 16);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(112, 24);
this.label3.TabIndex = 11;
this.label3.Text = "Initialization Vector";
//
// label4
//
this.label4.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label4.Location = new System.Drawing.Point(8, 16);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(72, 23);
this.label4.TabIndex = 10;
this.label4.Text = "Session Key";
//
// txtiv
//
this.txtiv.BackColor = System.Drawing.Color.Black;
this.txtiv.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.txtiv.ForeColor = System.Drawing.Color.Red;
this.txtiv.Location = new System.Drawing.Point(112, 40);
this.txtiv.Multiline = true;
this.txtiv.Name = "txtiv";
this.txtiv.ReadOnly = true;
this.txtiv.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.txtiv.Size = new System.Drawing.Size(100, 96);
this.txtiv.TabIndex = 9;
this.txtiv.Text = "";
//
// txtsk
//
this.txtsk.BackColor = System.Drawing.Color.Black;
this.txtsk.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.txtsk.ForeColor = System.Drawing.Color.LawnGreen;
this.txtsk.Location = new System.Drawing.Point(8, 40);
this.txtsk.Multiline = true;
this.txtsk.Name = "txtsk";
this.txtsk.ReadOnly = true;
this.txtsk.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.txtsk.Size = new System.Drawing.Size(100, 96);
this.txtsk.TabIndex = 8;
this.txtsk.Text = "";
//
// btngs
//
this.btngs.Location = new System.Drawing.Point(232, 40);
this.btngs.Name = "btngs";
this.btngs.TabIndex = 0;
this.btngs.Text = "Generation";
this.btngs.Click += new System.EventHandler(this.btngs_Click);
//
// btnds
//
this.btnds.Enabled = false;
this.btnds.Location = new System.Drawing.Point(232, 88);
this.btnds.Name = "btnds";
this.btnds.TabIndex = 3;
this.btnds.Text = "Decription";
this.btnds.Click += new System.EventHandler(this.btnds_Click);
//
// btnes
//
this.btnes.Enabled = false;
this.btnes.Location = new System.Drawing.Point(232, 64);
this.btnes.Name = "btnes";
this.btnes.TabIndex = 2;
this.btnes.Text = "Encription";
this.btnes.Click += new System.EventHandler(this.btnes_Click);
//
// groupBox3
//
this.groupBox3.Controls.Add(this.txtcipher);
this.groupBox3.Location = new System.Drawing.Point(52, 102);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(352, 96);
this.groupBox3.TabIndex = 17;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "Cipher Text";
//
// txtcipher
//
this.txtcipher.BackColor = System.Drawing.Color.Black;
this.txtcipher.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.txtcipher.Dock = System.Windows.Forms.DockStyle.Fill;
this.txtcipher.ForeColor = System.Drawing.Color.LawnGreen;
this.txtcipher.Location = new System.Drawing.Point(3, 16);
this.txtcipher.Multiline = true;
this.txtcipher.Name = "txtcipher";
this.txtcipher.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.txtcipher.Size = new System.Drawing.Size(346, 77);
this.txtcipher.TabIndex = 1;
this.txtcipher.Text = "";
//
// groupBox2
//
this.groupBox2.Controls.Add(this.txtplain);
this.groupBox2.Location = new System.Drawing.Point(52, 6);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(352, 96);
this.groupBox2.TabIndex = 16;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Plain Text";
//
// txtplain
//
this.txtplain.BackColor = System.Drawing.Color.White;
this.txtplain.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.txtplain.Dock = System.Windows.Forms.DockStyle.Fill;
this.txtplain.ForeColor = System.Drawing.Color.Black;
this.txtplain.Location = new System.Drawing.Point(3, 16);
this.txtplain.Multiline = true;
this.txtplain.Name = "txtplain";
this.txtplain.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.txtplain.Size = new System.Drawing.Size(346, 77);
this.txtplain.TabIndex = 1;
this.txtplain.Text = "It is a secrate Message";
//
// groupBox1
//
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Controls.Add(this.txtprk);
this.groupBox1.Controls.Add(this.txtpk);
this.groupBox1.Controls.Add(this.btnga);
this.groupBox1.Controls.Add(this.btnda);
this.groupBox1.Controls.Add(this.btnea);
this.groupBox1.Location = new System.Drawing.Point(52, 198);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(352, 152);
this.groupBox1.TabIndex = 15;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Asymetric Cryptography";
//
// label2
//
this.label2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label2.Location = new System.Drawing.Point(112, 16);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(72, 24);
this.label2.TabIndex = 11;
this.label2.Text = "Private Key";
//
// label1
//
this.label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label1.Location = new System.Drawing.Point(8, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(72, 23);
this.label1.TabIndex = 10;
this.label1.Text = "Public Key";
//
// txtprk
//
this.txtprk.BackColor = System.Drawing.Color.Black;
this.txtprk.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.txtprk.ForeColor = System.Drawing.Color.Red;
this.txtprk.Location = new System.Drawing.Point(112, 40);
this.txtprk.Multiline = true;
this.txtprk.Name = "txtprk";
this.txtprk.ReadOnly = true;
this.txtprk.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.txtprk.Size = new System.Drawing.Size(100, 96);
this.txtprk.TabIndex = 9;
this.txtprk.Text = "";
//
// txtpk
//
this.txtpk.BackColor = System.Drawing.Color.Black;
this.txtpk.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.txtpk.ForeColor = System.Drawing.Color.LawnGreen;
this.txtpk.Location = new System.Drawing.Point(8, 40);
this.txtpk.Multiline = true;
this.txtpk.Name = "txtpk";
this.txtpk.ReadOnly = true;
this.txtpk.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.txtpk.Size = new System.Drawing.Size(100, 96);
this.txtpk.TabIndex = 8;
this.txtpk.Text = "";
//
// btnga
//
this.btnga.Location = new System.Drawing.Point(232, 40);
this.btnga.Name = "btnga";
this.btnga.TabIndex = 0;
this.btnga.Text = "Generation";
this.btnga.Click += new System.EventHandler(this.btnga_Click);
//
// btnda
//
this.btnda.Enabled = false;
this.btnda.Location = new System.Drawing.Point(232, 88);
this.btnda.Name = "btnda";
this.btnda.TabIndex = 3;
this.btnda.Text = "Decription";
this.btnda.Click += new System.EventHandler(this.btnda_Click);
//
// btnea
//
this.btnea.Enabled = false;
this.btnea.Location = new System.Drawing.Point(232, 64);
this.btnea.Name = "btnea";
this.btnea.TabIndex = 2;
this.btnea.Text = "Encription";
this.btnea.Click += new System.EventHandler(this.btnea_Click);
//
// frmmain
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(456, 509);
this.Controls.Add(this.groupBox4);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Name = "frmmain";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Cryptography";
this.groupBox4.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new frmmain());
}
string pk,prk,sk,iv;
private void btnga_Click(object sender, System.EventArgs e)
{
AsymmetricCryptography asy = new AsymmetricCryptography();
prk = asy.Private_Key;
pk = asy.Public_Key;
txtpk.Text=pk;
txtprk.Text=prk;
btnea.Enabled=true;
btnda.Enabled=true;
btngs_Click(sender, e);
}
private void btnea_Click(object sender, System.EventArgs e)
{
AsymmetricCryptography asy = new AsymmetricCryptography();
asy.Private_Key = prk;
asy.Public_Key=pk;
txtcipher.Text = AsymmetricCryptography.Encript(txtplain.Text,asy.Public_Key);
btnds.Enabled=false;
btnes.Enabled= false;
txtplain.Clear();
}
private void btnda_Click(object sender, System.EventArgs e)
{
AsymmetricCryptography asy = new AsymmetricCryptography();
asy.Private_Key = prk;
asy.Public_Key=pk;
txtplain.Text = AsymmetricCryptography.Decript (txtcipher.Text,asy.Private_Key );
btnes.Enabled= true;
btnds.Enabled=true;
txtcipher.Clear();
}
private void btngs_Click(object sender, System.EventArgs e)
{
SymetricCryptography sym = new SymetricCryptography();
iv = sym.Initialization_Vector;
sk = sym.Sessio_Key;
txtiv.Text = iv;
txtsk.Text=sk;
btnes.Enabled= true;
btnds.Enabled=true;
}
private void btnes_Click(object sender, System.EventArgs e)
{
SymetricCryptography sym = new SymetricCryptography();
sym.Initialization_Vector = iv;
sym.Sessio_Key = sk;
txtcipher.Text= sym.EncryptString(txtplain.Text);
btnea.Enabled= false;
btnda.Enabled= false;
txtplain.Clear();
}
private void btnds_Click(object sender, System.EventArgs e)
{
SymetricCryptography sym = new SymetricCryptography();
sym.Initialization_Vector = iv;
sym.Sessio_Key = sk;
txtplain.Text= sym.DecryptString(txtcipher.Text);
btnda.Enabled=true;
btnea.Enabled= true;
txtcipher.Clear();
}
}
}