private bool blowFish() { bool ok = false; Stream stream = openFileDialog1.OpenFile(); if (keyTextBox.Text.Length > 0) { if (keyTextBox.Text.Length >= 8) { byte[] key; if (hexStringFlag.Checked) key = Encryption.GetBytesFromHexString(keyTextBox.Text); else key = Encryption.GetBytes(keyTextBox.Text); currentEncryption = new SHA256_Blowfish(key, stream); ok = true; } else MessageBox.Show("Blowfish needs atleast 8 bytes/characters as key"); } else { hexStringFlag.Checked = true; currentEncryption = new SHA256_Blowfish(stream); ok = true; } this.preEncryption = normalPreEncryption; this.duringEncryption = normalDuringEncryption; this.postEncrtypion = normalPostEncryption; return ok; }
private void DecryptButton_Click(object sender, EventArgs e) { currentOperation = OPERATION_DECRYPTION; switch (algorithmList.SelectedIndex) { case CAESARS_CIPHER: { Stream stream = openFileDialog1.OpenFile(); try { currentEncryption = new CaesarsCipherEncryption(stream, new Bitmap(100, 100)); ((CaesarsCipherEncryption)currentEncryption).DestinationFolder = destinationFileList.Text; EncryptionMeta output = new EncryptionMeta(); if (keyTextBox.Text.Length > 0) { output.Key = keyTextBox.Text; output.Output = new Bitmap(stream); stream.Close(); this.currentEncryption.Output = output; EncryptAndDecryptFunction(false); } else { MessageBox.Show("Please input key.", "Error"); keyTextBox.Focus(); } } catch (FileNotFoundException) { MessageBox.Show("No file selected", "Error"); } } break; case BLOWFISH: { Stream stream = openFileDialog1.OpenFile(); byte[] key; if (hexStringFlag.Checked) key = Encryption.GetBytesFromHexString(keyTextBox.Text); else key = Encryption.GetBytes(keyTextBox.Text); currentEncryption = new SHA256_Blowfish(key, null); ((SHA256_Blowfish)currentEncryption).DestinationFolder = destinationFileList.Text; EncryptionMeta output = new EncryptionMeta(); if (keyTextBox.Text.Length > 0) { output.Key = keyTextBox.Text; output.Output = new Bitmap(stream); Color color = output.Output.GetPixel(0, 0); stream.Close(); currentEncryption.Output = output; EncryptAndDecryptFunction(false); } } break; case OSIAS_ENCRYPTION: { if (keyTextBox.Text.Length > 0) { currentEncryption = new OSIASEncryption(null); OSIASEncryption enc = (OSIASEncryption)currentEncryption; enc.DataBitmap = new Bitmap(openFileDialog1.FileName); enc.KeyBitMap = new Bitmap(openFileDialog2.FileName); enc.Source = new FileStream(destinationFileList.Text + "\\output", FileMode.OpenOrCreate); this.preEncryption = normalPreEncryption; this.duringEncryption = normalDuringEncryption; this.postEncrtypion = OsiasPostDecryption; EncryptAndDecryptFunction(false); } } break; } }
private bool osiasEncryption() { bool ok = false; Stream stream = openFileDialog1.OpenFile(); this.currentEncryption = new OSIASEncryption(stream); this.preEncryption = normalPreEncryption; this.duringEncryption = normalDuringEncryption; this.postEncrtypion = OsiasPostEncryption; ok = true; return ok; }
private bool caesarscipher() { bool ok = false; Stream stream = openFileDialog1.OpenFile(); this.currentEncryption = new CaesarsCipherEncryption(stream, new Bitmap(100, 100), keyTextBox.Text); this.preEncryption = normalPreEncryption; this.duringEncryption = normalDuringEncryption; this.postEncrtypion = normalPostEncryption; ok = true; return ok; }