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

📄 cipherform.cs

📁 此工程实现了对文件
💻 CS
📖 第 1 页 / 共 2 页
字号:
			this.outputTextBox.Location = new System.Drawing.Point(168, 64);
			this.outputTextBox.Name = "outputTextBox";
			this.outputTextBox.Size = new System.Drawing.Size(288, 21);
			this.outputTextBox.TabIndex = 3;
			this.outputTextBox.Text = "";
			// 
			// FormatTabPage
			// 
			this.FormatTabPage.Controls.Add(this.openButton);
			this.FormatTabPage.Controls.Add(this.inputlable);
			this.FormatTabPage.Controls.Add(this.openTextBox);
			this.FormatTabPage.Controls.Add(this.Input);
			this.FormatTabPage.Controls.Add(this.button3);
			this.FormatTabPage.Controls.Add(this.fOutputButton);
			this.FormatTabPage.Controls.Add(this.formatOTextBox);
			this.FormatTabPage.Controls.Add(this.label7);
			this.FormatTabPage.Controls.Add(this.fInputButton);
			this.FormatTabPage.Controls.Add(this.formatTextBox);
			this.FormatTabPage.Controls.Add(this.label6);
			this.FormatTabPage.Controls.Add(this.cpuButton);
			this.FormatTabPage.Controls.Add(this.cpuTextBox);
			this.FormatTabPage.Controls.Add(this.label5);
			this.FormatTabPage.Location = new System.Drawing.Point(4, 21);
			this.FormatTabPage.Name = "FormatTabPage";
			this.FormatTabPage.Size = new System.Drawing.Size(624, 471);
			this.FormatTabPage.TabIndex = 2;
			this.FormatTabPage.Text = "Format File";
			// 
			// openButton
			// 
			this.openButton.Location = new System.Drawing.Point(192, 312);
			this.openButton.Name = "openButton";
			this.openButton.TabIndex = 13;
			this.openButton.Text = "Open";
			this.openButton.Click += new System.EventHandler(this.openButton_Click);
			// 
			// inputlable
			// 
			this.inputlable.Location = new System.Drawing.Point(400, 240);
			this.inputlable.Name = "inputlable";
			this.inputlable.TabIndex = 12;
			this.inputlable.Text = "input";
			this.inputlable.Click += new System.EventHandler(this.inputlable_Click);
			// 
			// openTextBox
			// 
			this.openTextBox.Location = new System.Drawing.Point(128, 240);
			this.openTextBox.Name = "openTextBox";
			this.openTextBox.Size = new System.Drawing.Size(224, 21);
			this.openTextBox.TabIndex = 11;
			this.openTextBox.Text = "";
			// 
			// Input
			// 
			this.Input.Location = new System.Drawing.Point(56, 248);
			this.Input.Name = "Input";
			this.Input.Size = new System.Drawing.Size(56, 23);
			this.Input.TabIndex = 10;
			this.Input.Text = "input:";
			// 
			// button3
			// 
			this.button3.Location = new System.Drawing.Point(192, 184);
			this.button3.Name = "button3";
			this.button3.TabIndex = 9;
			this.button3.Text = "Format";
			this.button3.Click += new System.EventHandler(this.button3_Click);
			// 
			// fOutputButton
			// 
			this.fOutputButton.Location = new System.Drawing.Point(400, 112);
			this.fOutputButton.Name = "fOutputButton";
			this.fOutputButton.TabIndex = 8;
			this.fOutputButton.Text = "output";
			this.fOutputButton.Click += new System.EventHandler(this.fOutputButton_Click);
			// 
			// formatOTextBox
			// 
			this.formatOTextBox.Location = new System.Drawing.Point(128, 112);
			this.formatOTextBox.Name = "formatOTextBox";
			this.formatOTextBox.Size = new System.Drawing.Size(208, 21);
			this.formatOTextBox.TabIndex = 7;
			this.formatOTextBox.Text = "";
			// 
			// label7
			// 
			this.label7.Location = new System.Drawing.Point(8, 120);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(112, 23);
			this.label7.TabIndex = 6;
			this.label7.Text = "Formated File:";
			// 
			// fInputButton
			// 
			this.fInputButton.Location = new System.Drawing.Point(400, 80);
			this.fInputButton.Name = "fInputButton";
			this.fInputButton.TabIndex = 5;
			this.fInputButton.Text = "input";
			this.fInputButton.Click += new System.EventHandler(this.fInputButton_Click);
			// 
			// formatTextBox
			// 
			this.formatTextBox.Location = new System.Drawing.Point(128, 80);
			this.formatTextBox.Name = "formatTextBox";
			this.formatTextBox.Size = new System.Drawing.Size(208, 21);
			this.formatTextBox.TabIndex = 4;
			this.formatTextBox.Text = "";
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(16, 80);
			this.label6.Name = "label6";
			this.label6.TabIndex = 3;
			this.label6.Text = "Format File:";
			// 
			// cpuButton
			// 
			this.cpuButton.Location = new System.Drawing.Point(400, 48);
			this.cpuButton.Name = "cpuButton";
			this.cpuButton.TabIndex = 2;
			this.cpuButton.Text = "cpu";
			this.cpuButton.Click += new System.EventHandler(this.cpuButton_Click);
			// 
			// cpuTextBox
			// 
			this.cpuTextBox.Location = new System.Drawing.Point(128, 48);
			this.cpuTextBox.Name = "cpuTextBox";
			this.cpuTextBox.Size = new System.Drawing.Size(208, 21);
			this.cpuTextBox.TabIndex = 1;
			this.cpuTextBox.Text = "";
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(40, 48);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(72, 23);
			this.label5.TabIndex = 0;
			this.label5.Text = "CPU NUM:";
			// 
			// openFileDialog1
			// 
			this.openFileDialog1.FileOk += new System.ComponentModel.CancelEventHandler(this.openFileDialog1_FileOk_1);
			// 
			// saveFileDialog1
			// 
			this.saveFileDialog1.FileOk += new System.ComponentModel.CancelEventHandler(this.saveFileDialog1_FileOk);
			// 
			// openFileDialog2
			// 
			this.openFileDialog2.FileOk += new System.ComponentModel.CancelEventHandler(this.openFileDialog2_FileOk);
			// 
			// CipherForm
			// 
			this.AllowDrop = true;
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(632, 494);
			this.Controls.Add(this.cipher);
			this.Name = "CipherForm";
			this.Text = "Rijndael";
			this.Load += new System.EventHandler(this.CipherForm_Load);
			this.cipher.ResumeLayout(false);
			this.cipherText.ResumeLayout(false);
			this.groupBox4.ResumeLayout(false);
			this.cipheredText.ResumeLayout(false);
			this.plainText.ResumeLayout(false);
			this.cipherFile.ResumeLayout(false);
			this.groupBox1.ResumeLayout(false);
			this.FormatTabPage.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

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

		private void CipherFile_Click(object sender, System.EventArgs e)
		{
		
		}

		private void cipherText_Click(object sender, System.EventArgs e)
		{
		
		}

		private void CipherForm_Load(object sender, System.EventArgs e)
		{
		
		}

		private void label1_Click(object sender, System.EventArgs e)
		{
		
		}

		private void encryptButton_Click(object sender, System.EventArgs e)
		{
			if (this.keyTextBox.Text == null || this.keyTextBox.Text.Length == 0) 
			{	
				return;

			} 
			else 
			{
				if (this.keyTextBox.Text.Length > 32)
					return;
				this.key = this.keyTextBox.Text;

			}

			this.ciphertextBox.Text = this.aes.EncryptText(key, this.palinTextBox.Text);
			this.ciphertextBox.Enabled = false;

		}



		private void dectyptButton_Click(object sender, System.EventArgs e)
		{
			if (this.keyTextBox.Text == null || this.keyTextBox.Text.Length == 0) 
			{	
				return;

			} 
			else 
			{
				if (this.keyTextBox.Text.Length > 32)
					return;
				this.key = this.keyTextBox.Text;

			}
			this.textBox4.Text = this.aes.DecryptText(key, this.ciphertextBox.Text);
		}

		private void textBox4_TextChanged(object sender, System.EventArgs e)
		{
		
		}

		private void label2_Click(object sender, System.EventArgs e)
		{
		
		}

		private void openFileDialog1_FileOk(object sender, System.ComponentModel.CancelEventArgs e)
		{
		
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			this.openFileDialog1.ShowDialog();
		}

		private void openFileDialog1_FileOk_1(object sender, System.ComponentModel.CancelEventArgs e)
		{
			this.inputTextBox.Text = openFileDialog1.FileName;
			this.formatTextBox.Text = openFileDialog1.FileName;
		}

		private void button2_Click(object sender, System.EventArgs e)
		{
			this.saveFileDialog1.ShowDialog();
		}

		private void saveFileDialog1_FileOk(object sender, System.ComponentModel.CancelEventArgs e)
		{
			this.outputTextBox.Text = saveFileDialog1.FileName;
			this.formatOTextBox.Text = saveFileDialog1.FileName;
		}

		private void enButton_Click(object sender, System.EventArgs e)
		{
			this.aes = new Aes();
			if (this.fileKeyTextBox.Text == null || this.fileKeyTextBox.Text.Length == 0) 
			{	
				return;

			} 
			else 
			{
				if (this.fileKeyTextBox.Text.Length > 32)
					return;
				this.key = this.fileKeyTextBox.Text;
			}
			String input = this.inputTextBox.Text;
			String output = this.outputTextBox.Text;

			this.aes.EncryptFile(this.aes.GetKey(this.key), input, output);
		}

		private void deButton_Click(object sender, System.EventArgs e)
		{
			this.aes = new Aes();
			if (this.fileKeyTextBox.Text == null || this.fileKeyTextBox.Text.Length == 0) 
			{	
				return;
			} 
			else 
			{
				if (this.fileKeyTextBox.Text.Length > 32)
					return;
				this.key = this.fileKeyTextBox.Text;
			}
			String input = this.inputTextBox.Text;
			String output = this.outputTextBox.Text;
			this.aes.DecryptFile(this.aes.GetKey(this.key), input, output);
		
		}

		private void cpuButton_Click(object sender, System.EventArgs e)
		{
			RSFormator formator = new RSFormator();
			this.cpuTextBox.Text = formator.GeneratKey();
			this.label5.Text = formator.GeneratKey().Length.ToString();
		}

		private void fInputButton_Click(object sender, System.EventArgs e)
		{
		    this.openFileDialog1.ShowDialog();
		}

		private void fOutputButton_Click(object sender, System.EventArgs e)
		{
			this.saveFileDialog1.ShowDialog();
		}

		private void inputlable_Click(object sender, System.EventArgs e)
		{
			this.openFileDialog2.ShowDialog();
		}

		private void openFileDialog2_FileOk(object sender, System.ComponentModel.CancelEventArgs e)
		{
			this.openTextBox.Text = this.openFileDialog2.FileName;
		}

		private void button3_Click(object sender, System.EventArgs e)
		{
			String key = this.cpuTextBox.Text;
			String input = this.formatTextBox.Text;
			String output = this.formatOTextBox.Text;

			FileStream outStream = new FileStream(output,
				FileMode.Create,
				FileAccess.Write);
			byte[] keyInBytes = this.aes.GetKey(key);
			byte []result = this.aes.EncryptFile(keyInBytes, input);
			
			BinaryWriter w = new BinaryWriter(outStream);
			w.Write(keyInBytes);
			w.Write(result);
			w.Flush();
			w.Close();

		}

		private void openButton_Click(object sender, System.EventArgs e)
		{
			String input = this.openTextBox.Text;
			FileStream fsInput = new FileStream(input,
				FileMode.Open,
				FileAccess.Read);
			byte []keyb = new byte[16];
			byte []fileBytes = new byte[fsInput.Length];
			fsInput.Read(keyb, 0,16);
            
			fsInput.Read(fileBytes, 16, (int)fsInput.Length - 16);
			fsInput.Close();
			this.label6.Text = Encoding.UTF8.GetString(keyb);



		}
	}
}

⌨️ 快捷键说明

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