private void buttonStartClick(object sender, EventArgs e) { if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA) { Thread thread = new Thread(new ThreadStart(delegate { buttonStartClick(sender, e); })); thread.IsBackground = true; thread.Start(); return; } Rijndael aes = new Rijndael(Tools.StringToBytes(textBoxKey.Text)); Stream messageFile = new PKCSPaddedStream(aes, new FileStream(labelMessage.Text, FileMode.OpenOrCreate)), cipherFile = new FileStream(labelCipher.Text, FileMode.OpenOrCreate); IBlockCipherMode blockMode = null; if (radioButtonCFB.Checked) blockMode = new CipherFeedback(aes, Tools.StringToBytes(textBoxIv.Text)); else if (radioButtonCTR.Checked) blockMode = new SegmentedIntegerCounter(aes, Tools.StringToBytes(textBoxIv.Text)); else if (radioButtonECB.Checked) blockMode = new ElectronicCodeBook(aes); else if (radioButtonCBC.Checked) blockMode = new CipherBlockChaining(aes, Tools.StringToBytes(textBoxIv.Text)); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); long bytes; if (radioButtonEncrypt.Checked) { bytes = messageFile.Length; blockMode.Encrypt(messageFile, cipherFile); } else { bytes = cipherFile.Length; blockMode.Decrypt(cipherFile, messageFile); } stopwatch.Stop(); Console.WriteLine(stopwatch.Elapsed + " (" + (stopwatch.Elapsed.Ticks / bytes) + " ticks/byte)"); MessageBox.Show("Cryption done!", stopwatch.Elapsed + " (" + (stopwatch.Elapsed.Ticks / bytes) + " ticks/byte)"); messageFile.Close(); cipherFile.Close(); }
public ChatTab(IBlockCipher cipher, PKCSPaddedStream stream, Socket socket) : base() { this.cipher = cipher; this.stream = stream; Text = socket.RemoteEndPoint.ToString(); textBox.Multiline = true; textBox.ReadOnly = true; textBox.Size = new Size(479, 399); textBox.Location = new Point(6, 6); textBox.Font = new Font("Consolas", 10); Controls.Add(textBox); }