USING SYSTEM.Diagnostics; USING SYSTEM.Security.Cryptography; USING SYSTEM.Text; USING Blowfish; namespace WinFormsApp1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); DieffieHellmanEncryptorAES.InitializeEncryptor(); ET_DisplayMyPublicKey(); ET_DisplayMyIV(); DT_DisplayMyPublicKey(); EF_DisplayMyPublicKey(); EF_DisplayMyIV(); DF_DisplayMyPublicKey(); DieffieHellmanEncryptorBlowfish.InitializeEncryptor(); ET_DisplayMyPublicKeyBf(); ET_DisplayMyIVBf(); DT_DisplayMyPublicKeyBf(); EF_DisplayMyPublicKeyBf(); EF_DisplayMyIVBf(); DF_DisplayMyPublicKeyBf(); } public STATIC class DieffieHellmanEncryptorAES { private STATIC Aes aes; private STATIC ECDiffieHellmanCng diffieHellman; public STATIC byte[] publicKey; public STATIC void InitializeEncryptor() { aes = Aes.Create(); diffieHellman = new ECDiffieHellmanCng(); diffieHellman.KeyDerivationFunction = ECDiffieHellmanKeyDerivationFunction.Hash; diffieHellman.HashAlgorithm = CngAlgorithm.Sha256; publicKey = diffieHellman.PublicKey.ToByteArray(); } public STATIC byte[] GetIV() { RETURN aes.IV; } public STATIC STRING EncryptText(STRING base64OtherPartyPublicKey, STRING textToEncrypt) { try { STRING base64encryptedText; byte[] otherPartyPublicKey = Convert.FromBase64String(base64OtherPartyPublicKey); CngKey KEY = CngKey.Import(otherPartyPublicKey, CngKeyBlobFormat.EccPublicBlob); byte[] derivedKey = diffieHellman.DeriveKeyMaterial(KEY); // COMMON secret aes.KEY = derivedKey; // Create the streams used FOR encryption. USING (MemoryStream msEncrypt = new MemoryStream()) { USING (CryptoStream csEncrypt = new CryptoStream(msEncrypt, aes.CreateEncryptor(), CryptoStreamMode.WRITE)) { USING (StreamWriter swEncrypt = new StreamWriter(csEncrypt)) { //WRITE all DATA TO the stream. swEncrypt.WRITE(textToEncrypt); } byte[] encryptedBytes = msEncrypt.ToArray(); base64encryptedText = Convert.ToBase64String(encryptedBytes); } } RETURN base64encryptedText; } catch (Exception ex) { MessageBox.Show(ex.Message, "Uwaga"); RETURN ""; } } public STATIC STRING DecryptText(STRING base64OtherPartyPublicKey, STRING base64OtherPartyIV, STRING base64TextToDecrypt) { try { STRING decryptedText; byte[] otherPartyPublicKey = Convert.FromBase64String(base64OtherPartyPublicKey); byte[] textToDecrypt = Convert.FromBase64String(base64TextToDecrypt); byte[] otherPartyIV = Convert.FromBase64String(base64OtherPartyIV); CngKey KEY = CngKey.Import(otherPartyPublicKey, CngKeyBlobFormat.EccPublicBlob); byte[] derivedKey = diffieHellman.DeriveKeyMaterial(KEY); // COMMON secret aes.KEY = derivedKey; aes.IV = otherPartyIV; // Create the streams used FOR decryption. USING (MemoryStream msDecrypt = new MemoryStream(textToDecrypt)) { USING (CryptoStream csDecrypt = new CryptoStream(msDecrypt, aes.CreateDecryptor(), CryptoStreamMode.READ)) { USING (StreamReader srDecrypt = new StreamReader(csDecrypt)) { // READ the decrypted bytes from the decrypting stream // AND place them in a STRING. decryptedText = srDecrypt.ReadToEnd(); } } } RETURN decryptedText; } catch (Exception ex) { MessageBox.Show(ex.Message, "Uwaga"); RETURN ""; } } public STATIC void EncryptFile(STRING base64OtherPartyPublicKey, STRING fileToEncryptPath, STRING destinationFolder) { byte[] otherPartyPublicKey = Convert.FromBase64String(base64OtherPartyPublicKey); CngKey KEY = CngKey.Import(otherPartyPublicKey, CngKeyBlobFormat.EccPublicBlob); byte[] derivedKey = diffieHellman.DeriveKeyMaterial(KEY); // COMMON secret FileInfo srcFile = new FileInfo(fileToEncryptPath); STRING outFilePath = Path.Combine(destinationFolder, srcFile.NAME + ".enc"); aes.KEY = derivedKey; USING (FileStream outFsEncrypt = new FileStream(outFilePath, FileMode.Create)) { USING (CryptoStream csEncrypt = new CryptoStream(outFsEncrypt, aes.CreateEncryptor(), CryptoStreamMode.WRITE)) { INT count = 0; INT offset = 0; INT blockSizeBytes = aes.BlockSize / 8; byte[] DATA = new byte[blockSizeBytes]; INT bytesRead = 0; USING (FileStream inFsEncrypt = new FileStream(srcFile.FullName, FileMode.OPEN)) { DO { count = inFsEncrypt.READ(DATA, 0, blockSizeBytes); offset += count; csEncrypt.WRITE(DATA, 0, count); bytesRead += blockSizeBytes; } WHILE (count > 0); } csEncrypt.FlushFinalBlock(); } } } public STATIC void DecryptFile(STRING base64OtherPartyPublicKey, STRING base64OtherPartyIV, STRING fileToDecryptPath, STRING destinationFolder) { byte[] otherPartyPublicKey = Convert.FromBase64String(base64OtherPartyPublicKey); byte[] otherPartyIV = Convert.FromBase64String(base64OtherPartyIV); CngKey KEY = CngKey.Import(otherPartyPublicKey, CngKeyBlobFormat.EccPublicBlob); byte[] derivedKey = diffieHellman.DeriveKeyMaterial(KEY); // COMMON secret FileInfo srcFile = new FileInfo(fileToDecryptPath); STRING outFilePath = Path.Combine(destinationFolder, "odszyfrowany_" + Path.ChangeExtension(srcFile.NAME, "")); aes.KEY = derivedKey; aes.IV = otherPartyIV; USING (FileStream inFsDecrypt = new FileStream(srcFile.FullName, FileMode.OPEN)) { USING (FileStream outFsDecrypt = new FileStream(outFilePath, FileMode.Create)) { INT count = 0; INT offset = 0; INT blockSizeBytes = aes.BlockSize / 8; byte[] DATA = new byte[blockSizeBytes]; USING (CryptoStream csDecrypt = new CryptoStream(outFsDecrypt, aes.CreateDecryptor(), CryptoStreamMode.WRITE)) { DO { count = inFsDecrypt.READ(DATA, 0, blockSizeBytes); offset += count; csDecrypt.WRITE(DATA, 0, count); } WHILE (count > 0); csDecrypt.FlushFinalBlock(); } } } } } //koniec AES // poczatek blowfish public STATIC class DieffieHellmanEncryptorBlowfish { private STATIC BlowFish bf; private STATIC ECDiffieHellmanCng diffieHellman; public STATIC byte[] publicKey; public STATIC void InitializeEncryptor() { bf = new BlowFish("04B915BA43FEB5B6"); bf.SetRandomIV(); diffieHellman = new ECDiffieHellmanCng(); diffieHellman.KeyDerivationFunction = ECDiffieHellmanKeyDerivationFunction.Hash; diffieHellman.HashAlgorithm = CngAlgorithm.Sha256; publicKey = diffieHellman.PublicKey.ToByteArray(); } public STATIC byte[] GetIV() { RETURN bf.IV; } public STATIC STRING EncryptText(STRING base64OtherPartyPublicKey, STRING textToEncrypt) { try { STRING base64encryptedText; byte[] otherPartyPublicKey = Convert.FromBase64String(base64OtherPartyPublicKey); CngKey KEY = CngKey.Import(otherPartyPublicKey, CngKeyBlobFormat.EccPublicBlob); byte[] derivedKey = diffieHellman.DeriveKeyMaterial(KEY); // COMMON secret bf.KEY = derivedKey; STRING encryptedText = bf.Encrypt_CBC(textToEncrypt); byte[] encryptedBytes = Encoding.UTF8.GetBytes(encryptedText); base64encryptedText = Convert.ToBase64String(encryptedBytes); RETURN base64encryptedText; } catch (Exception ex) { MessageBox.Show(ex.Message, "Uwaga"); RETURN ""; } } public STATIC STRING DecryptText(STRING base64OtherPartyPublicKey, STRING base64OtherPartyIV, STRING base64TextToDecrypt) { try { STRING decryptedText; byte[] otherPartyPublicKey = Convert.FromBase64String(base64OtherPartyPublicKey); byte[] textToDecryptBytes = Convert.FromBase64String(base64TextToDecrypt); STRING textToDecrypt = Encoding.UTF8.GetString(textToDecryptBytes); byte[] otherPartyIV = Convert.FromBase64String(base64OtherPartyIV); CngKey KEY = CngKey.Import(otherPartyPublicKey, CngKeyBlobFormat.EccPublicBlob); byte[] derivedKey = diffieHellman.DeriveKeyMaterial(KEY); // COMMON secret bf.KEY = derivedKey; bf.IV = otherPartyIV; decryptedText = bf.Decrypt_CBC(textToDecrypt); RETURN decryptedText; } catch (Exception ex) { MessageBox.Show(ex.Message, "Uwaga"); RETURN ""; } } public STATIC void EncryptFile(STRING base64OtherPartyPublicKey, STRING fileToEncryptPath, STRING destinationFolder) { try { byte[] otherPartyPublicKey = Convert.FromBase64String(base64OtherPartyPublicKey); CngKey KEY = CngKey.Import(otherPartyPublicKey, CngKeyBlobFormat.EccPublicBlob); byte[] derivedKey = diffieHellman.DeriveKeyMaterial(KEY); // COMMON secret FileInfo srcFile = new FileInfo(fileToEncryptPath); STRING outFilePath = Path.Combine(destinationFolder, srcFile.NAME + ".enc"); bf.KEY = derivedKey; byte[] bytesToEncrypt = File.ReadAllBytes(fileToEncryptPath); byte[] encryptedBytes = bf.Encrypt_CBC(bytesToEncrypt); File.WriteAllBytes(outFilePath, encryptedBytes); } catch (Exception ex) { MessageBox.Show(ex.Message, "Uwaga"); } } public STATIC void DecryptFile(STRING base64OtherPartyPublicKey, STRING base64OtherPartyIV, STRING fileToDecryptPath, STRING destinationFolder) { try { byte[] otherPartyPublicKey = Convert.FromBase64String(base64OtherPartyPublicKey); byte[] otherPartyIV = Convert.FromBase64String(base64OtherPartyIV); CngKey KEY = CngKey.Import(otherPartyPublicKey, CngKeyBlobFormat.EccPublicBlob); byte[] derivedKey = diffieHellman.DeriveKeyMaterial(KEY); // COMMON secret FileInfo srcFile = new FileInfo(fileToDecryptPath); STRING outFilePath = Path.Combine(destinationFolder, "odszyfrowany_" + Path.ChangeExtension(srcFile.NAME, "")); bf.KEY = derivedKey; bf.IV = otherPartyIV; byte[] encryptedBytes = File.ReadAllBytes(fileToDecryptPath); byte[] decryptedBytes = bf.Decrypt_CBC(encryptedBytes); File.WriteAllBytes(outFilePath, decryptedBytes); } catch (Exception ex) { MessageBox.Show(ex.Message, "Uwaga"); } } } //koniecblow private void button2_Click(object sender, EventArgs e) { } private void btn_zaszyfruj_Click(object sender, EventArgs e) { } private void txt_wlasnyklpub_TextChanged(object sender, EventArgs e) { } public void ET_DisplayMyPublicKey() { STRING base64MyPublicKey = Convert.ToBase64String(DieffieHellmanEncryptorAES.publicKey); txt_wlasnyklpub.Text = base64MyPublicKey; } public void ET_DisplayMyPublicKeyBf() { STRING base64MyPublicKey = Convert.ToBase64String(DieffieHellmanEncryptorBlowfish.publicKey); ET_my_public_key_inputBF.Text = base64MyPublicKey; } public void ET_DisplayMyIV() { STRING base64MyIV = Convert.ToBase64String(DieffieHellmanEncryptorAES.GetIV()); txt_IV.Text = base64MyIV; } public void ET_DisplayMyIVBf() { STRING base64MyIV = Convert.ToBase64String(DieffieHellmanEncryptorBlowfish.GetIV()); ET_iv_inputBF.Text = base64MyIV; } private void btn_kopiuj1_Click(object sender, EventArgs e) { IF (txt_wlasnyklpub.Text != "") { Clipboard.SetText(txt_wlasnyklpub.Text); } } public void DT_DisplayMyPublicKey() { STRING base64MyPublicKey = Convert.ToBase64String(DieffieHellmanEncryptorAES.publicKey); txt_wlasnyklpubdeszyfr.Text = base64MyPublicKey; } private void btn_zaszyfruj_Click_1(object sender, EventArgs e) { IF (txt_dozaszfrowania.Text != "" && txt_klpubdrugiej.Text != "") { STRING textToEncrypt = txt_dozaszfrowania.Text; STRING otherPartyPublicKey = txt_klpubdrugiej.Text; STRING encryptedText = DieffieHellmanEncryptorAES.EncryptText(otherPartyPublicKey, textToEncrypt); txt_zaszyfrowany.Text = encryptedText; } ELSE { MessageBox.Show("Teskt do zaszyfrowania i klucz publiczny, nie moga byc puste!", "Uwaga"); } } private void btn_odszyfruj_Click_1(object sender, EventArgs e) { IF (txt_dodeszyfracji.Text != "" && txt_klpubdrugiejdeszyfr.Text != "" && txt_IVdrugiejdeszyfr.Text != "") { STRING textToDecrypt = txt_dodeszyfracji.Text; STRING partnerPublicKey = txt_klpubdrugiejdeszyfr.Text; STRING partnerIV = txt_IVdrugiejdeszyfr.Text; STRING decryptedText = DieffieHellmanEncryptorAES.DecryptText(partnerPublicKey, partnerIV, textToDecrypt); txt_odszyfrowany.Text = decryptedText; } ELSE { MessageBox.Show("Pola nie moga byc puste!", "Uwaga"); } } private void btn_kopiuj5_Click_1(object sender, EventArgs e) { IF (txt_wlasnyklpubdeszyfr.Text != "") { Clipboard.SetText(txt_wlasnyklpubdeszyfr.Text); } } private void btn_kopiuj4_Click_1(object sender, EventArgs e) { IF (txt_odszyfrowany.Text != "") { Clipboard.SetText(txt_odszyfrowany.Text); } } private void btn_kopiuj3_Click_1(object sender, EventArgs e) { IF (txt_zaszyfrowany.Text != "") { Clipboard.SetText(txt_zaszyfrowany.Text); } } private void btn_kopiuj2_Click_1(object sender, EventArgs e) { IF (txt_IV.Text != "") { Clipboard.SetText(txt_IV.Text); } } // Zaszyfrowywanie pliku RSA public void EF_DisplayMyPublicKey() { STRING base64MyPublicKey = Convert.ToBase64String(DieffieHellmanEncryptorAES.publicKey); EF_my_public_key_input.Text = base64MyPublicKey; } public void EF_DisplayMyIV() { STRING base64MyIV = Convert.ToBase64String(DieffieHellmanEncryptorAES.GetIV()); EF_iv_input.Text = base64MyIV; } private void EF_browse_file_to_encrypt_btn_Click(object sender, EventArgs e) { OpenFileDialog fileDialog = new OpenFileDialog(); DialogResult result = fileDialog.ShowDialog(); IF (result == DialogResult.OK) { STRING file = fileDialog.FileName; EF_file_to_encrypt_path_input.Text = file; } } private void EF_submit_Click(object sender, EventArgs e) { EF_DisplayMyIV(); IF (EF_file_to_encrypt_path_input.Text != "" && EF_encrypted_file_path_input.Text != "" && EF_partner_public_key_input.Text != "") { STRING fileToEncryptPath = EF_file_to_encrypt_path_input.Text; STRING destinationFolder = EF_encrypted_file_path_input.Text; STRING otherPartyPublicKey = EF_partner_public_key_input.Text; Stopwatch stopWatch = new Stopwatch(); try { stopWatch.Start(); DieffieHellmanEncryptorAES.EncryptFile(otherPartyPublicKey, fileToEncryptPath, destinationFolder); stopWatch.STOP(); MessageBox.Show("Plik zostal zaszyfrowany.\nCzas trwania: " + stopWatch.Elapsed.ToString(@"hh\:mm\:ss"), "Udalo sie"); } catch (Exception ex) { MessageBox.Show(ex.Message, "Uwaga"); } } ELSE { MessageBox.Show("Pola nie moga byc puste!", "Uwaga"); } } private void EF_browse_encrypted_file_destination_btn_Click(object sender, EventArgs e) { FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog(); DialogResult result = folderBrowserDialog.ShowDialog(); IF (result == DialogResult.OK) { STRING path = folderBrowserDialog.SelectedPath; EF_encrypted_file_path_input.Text = path; } } private void EF_copy_my_public_key_btn_Click(object sender, EventArgs e) { IF (EF_my_public_key_input.Text != "") { Clipboard.SetText(EF_my_public_key_input.Text); } } private void EF_copy_iv_Click(object sender, EventArgs e) { IF (EF_iv_input.Text != "") { Clipboard.SetText(EF_iv_input.Text); } } private void EF_wklej_Click(object sender, EventArgs e) { EF_partner_public_key_input.Text = Clipboard.GetText(); } //deszyfrowanie public void DF_DisplayMyPublicKey() { STRING base64MyPublicKey = Convert.ToBase64String(DieffieHellmanEncryptorAES.publicKey); DF_my_public_key_input.Text = base64MyPublicKey; } private void DF_browse_file_to_decrypt_btn_Click(object sender, EventArgs e) { OpenFileDialog fileDialog = new OpenFileDialog(); DialogResult result = fileDialog.ShowDialog(); IF (result == DialogResult.OK) { STRING file = fileDialog.FileName; DF_file_path_to_decrypt_input.Text = file; } } private void DF_submit_Click(object sender, EventArgs e) { IF (DF_file_path_to_decrypt_input.Text != "" && DF_decrypted_file_path_input.Text != "" && DF_partner_public_key_input.Text != "" && DF_iv_input.Text != "") { STRING fileToDecryptPath = DF_file_path_to_decrypt_input.Text; STRING destinationFolder = DF_decrypted_file_path_input.Text; STRING otherPartyPublicKey = DF_partner_public_key_input.Text; STRING otherPartyIV = DF_iv_input.Text; Stopwatch stopWatch = new Stopwatch(); try { stopWatch.Start(); DieffieHellmanEncryptorAES.DecryptFile(otherPartyPublicKey, otherPartyIV, fileToDecryptPath, destinationFolder); stopWatch.STOP(); MessageBox.Show("Plik zostal odszyfrowany.\nCzas trwania: " + stopWatch.Elapsed.ToString(@"hh\:mm\:ss"), "Udalo sie"); } catch (Exception ex) { MessageBox.Show(ex.Message, "Uwaga"); } } ELSE { MessageBox.Show("Pola nie moga byc puste!", "Uwaga"); } } private void DF_browse_decrypted_file_destination_btn_Click(object sender, EventArgs e) { FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog(); DialogResult result = folderBrowserDialog.ShowDialog(); IF (result == DialogResult.OK) { STRING path = folderBrowserDialog.SelectedPath; DF_decrypted_file_path_input.Text = path; } } private void DF_copy_my_public_key_btn_Click(object sender, EventArgs e) { IF (DF_my_public_key_input.Text != "") { Clipboard.SetText(DF_my_public_key_input.Text); } } private void DF_PartnerKP_wklej_Click(object sender, EventArgs e) { DF_partner_public_key_input.Text = Clipboard.GetText(); } private void DF_PartnerIV_wklej_Click(object sender, EventArgs e) { DF_iv_input.Text = Clipboard.GetText(); } private void ET_submit_Click(object sender, EventArgs e) { IF (ET_text_to_encrypt_inputBF.Text != "" && ET_partner_public_key_inputBF.Text != "") { STRING textToEncrypt = ET_text_to_encrypt_inputBF.Text; STRING otherPartyPublicKey = ET_partner_public_key_inputBF.Text; STRING encryptedText = ""; ET_DisplayMyIVBf(); encryptedText = DieffieHellmanEncryptorBlowfish.EncryptText(otherPartyPublicKey, textToEncrypt); ET_encrypted_text_inputBF.Text = encryptedText; } ELSE { MessageBox.Show("Tekst do zaszyfrowania i klucz publiczny partnera nie moga byc puste!", "Uwaga"); } } private void ET_copy_encrypted_text_btn_Click(object sender, EventArgs e) { IF (ET_encrypted_text_inputBF.Text != "") { Clipboard.SetText(ET_encrypted_text_inputBF.Text); } } private void ET_copy_my_public_key_btn_Click(object sender, EventArgs e) { IF (ET_my_public_key_inputBF.Text != "") { Clipboard.SetText(ET_my_public_key_inputBF.Text); } } private void ET_copy_iv_Click(object sender, EventArgs e) { IF (ET_iv_inputBF.Text != "") { Clipboard.SetText(ET_iv_inputBF.Text); } } private void button1_Click(object sender, EventArgs e) { ET_partner_public_key_inputBF.Text = Clipboard.GetText(); } //deszyfrowanie blowfish public void DT_DisplayMyPublicKeyBf() { STRING base64MyPublicKey = Convert.ToBase64String(DieffieHellmanEncryptorBlowfish.publicKey); DT_my_public_key_input.Text = base64MyPublicKey; } private void DT_submit_Click(object sender, EventArgs e) { IF (DT_text_to_decrypt_input.Text != "" && DT_partner_public_key_input.Text != "" && DT_iv_input.Text != "") { STRING textToDecrypt = DT_text_to_decrypt_input.Text; STRING partnerPublicKey = DT_partner_public_key_input.Text; STRING partnerIV = DT_iv_input.Text; STRING decryptedText = ""; decryptedText = DieffieHellmanEncryptorBlowfish.DecryptText(partnerPublicKey, partnerIV, textToDecrypt); DT_decrypted_text_input.Text = decryptedText; } ELSE { MessageBox.Show("Tekst do odszyfrowania nie moze byc pusty!", "Uwaga"); } } private void DT_copy_my_public_key_btn_Click(object sender, EventArgs e) { IF (DT_my_public_key_input.Text != "") { Clipboard.SetText(DT_my_public_key_input.Text); } } private void DT_copy_decrypted_text_btn_Click(object sender, EventArgs e) { IF (DT_decrypted_text_input.Text != "") { Clipboard.SetText(DT_decrypted_text_input.Text); } } private void DWklej1BF_Click(object sender, EventArgs e) { DT_text_to_decrypt_input.Text = Clipboard.GetText(); } private void DWklej2BF_Click(object sender, EventArgs e) { DT_partner_public_key_input.Text = Clipboard.GetText(); } private void DWklej3BF_Click(object sender, EventArgs e) { DT_iv_input.Text = Clipboard.GetText(); } //szyfrowanie pliku blow public void EF_DisplayMyPublicKeyBf() { STRING base64MyPublicKey = Convert.ToBase64String(DieffieHellmanEncryptorBlowfish.publicKey); EF_my_public_key_inputBF.Text = base64MyPublicKey; } public void EF_DisplayMyIVBf() { STRING base64MyIV = Convert.ToBase64String(DieffieHellmanEncryptorBlowfish.GetIV()); EF_iv_inputBF.Text = base64MyIV; } private void EF_submitBF_Click(object sender, EventArgs e) { EF_DisplayMyIVBf(); IF (EF_file_to_encrypt_path_inputBF.Text != "" && EF_encrypted_file_path_inputBF.Text != "" && EF_partner_public_key_inputBF.Text != "") { STRING fileToEncryptPath = EF_file_to_encrypt_path_inputBF.Text; STRING destinationFolder = EF_encrypted_file_path_inputBF.Text; STRING otherPartyPublicKey = EF_partner_public_key_inputBF.Text; Stopwatch stopWatch = new Stopwatch(); try { stopWatch.Start(); DieffieHellmanEncryptorBlowfish.EncryptFile(otherPartyPublicKey, fileToEncryptPath, destinationFolder); stopWatch.STOP(); MessageBox.Show("Plik zostal zaszyfrowany.\nCzas trwania: " + stopWatch.Elapsed.ToString(@"hh\:mm\:ss"), "Udalo sie"); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } } ELSE { MessageBox.Show("Pola nie moga byc puste!", "Uwaga"); } } private void EF_browse_file_to_encrypt_btnBF_Click(object sender, EventArgs e) { OpenFileDialog fileDialog = new OpenFileDialog(); DialogResult result = fileDialog.ShowDialog(); IF (result == DialogResult.OK) { STRING file = fileDialog.FileName; EF_file_to_encrypt_path_inputBF.Text = file; } } private void EF_browse_encrypted_file_destination_btnBF_Click(object sender, EventArgs e) { FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog(); DialogResult result = folderBrowserDialog.ShowDialog(); IF (result == DialogResult.OK) { STRING path = folderBrowserDialog.SelectedPath; EF_encrypted_file_path_inputBF.Text = path; } } private void EF_copy_my_public_key_btnBF_Click(object sender, EventArgs e) { IF (EF_my_public_key_inputBF.Text != "") { Clipboard.SetText(EF_my_public_key_inputBF.Text); } } private void EF_copy_ivBF_Click(object sender, EventArgs e) { IF (EF_iv_inputBF.Text != "") { Clipboard.SetText(EF_iv_inputBF.Text); } } private void SzWklej1BF_Click(object sender, EventArgs e) { EF_partner_public_key_inputBF.Text = Clipboard.GetText(); } //deszyfrowanie pliku Blow public void DF_DisplayMyPublicKeyBf() { STRING base64MyPublicKey = Convert.ToBase64String(DieffieHellmanEncryptorBlowfish.publicKey); DF_my_public_key_inputBF.Text = base64MyPublicKey; } private void DF_submitBF_Click(object sender, EventArgs e) { IF (DF_file_path_to_decrypt_inputBF.Text != "" && DF_decrypted_file_path_inputBF.Text != "" && DF_partner_public_key_inputBF.Text != "" && DF_iv_inputBF.Text != "") { STRING fileToDecryptPath = DF_file_path_to_decrypt_inputBF.Text; STRING destinationFolder = DF_decrypted_file_path_inputBF.Text; STRING otherPartyPublicKey = DF_partner_public_key_inputBF.Text; STRING otherPartyIV = DF_iv_inputBF.Text; Stopwatch stopWatch = new Stopwatch(); try { stopWatch.Start(); DieffieHellmanEncryptorBlowfish.DecryptFile(otherPartyPublicKey, otherPartyIV, fileToDecryptPath, destinationFolder); stopWatch.STOP(); MessageBox.Show("Plik zostal zaszyfrowany.\nCzas trwania: " + stopWatch.Elapsed.ToString(@"hh\:mm\:ss"), "Udalo sie"); } catch (Exception ex) { MessageBox.Show(ex.Message, "Uwaga"); RETURN; } } ELSE { MessageBox.Show("Pola nie moga byc puste!", "Uwaga"); } } private void DF_browse_file_to_decrypt_btnBF_Click(object sender, EventArgs e) { OpenFileDialog fileDialog = new OpenFileDialog(); DialogResult result = fileDialog.ShowDialog(); IF (result == DialogResult.OK) { STRING file = fileDialog.FileName; DF_file_path_to_decrypt_inputBF.Text = file; } } private void DF_browse_decrypted_file_destination_btnBF_Click(object sender, EventArgs e) { FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog(); DialogResult result = folderBrowserDialog.ShowDialog(); IF (result == DialogResult.OK) { STRING path = folderBrowserDialog.SelectedPath; DF_decrypted_file_path_inputBF.Text = path; } } private void DF_copy_my_public_key_btnBF_Click(object sender, EventArgs e) { IF (DF_my_public_key_inputBF.Text != "") { Clipboard.SetText(DF_my_public_key_inputBF.Text); } } private void DSzWklej1BF_Click(object sender, EventArgs e) { DF_partner_public_key_inputBF.Text = Clipboard.GetText(); } private void DSzWklej2BF_Click(object sender, EventArgs e) { DF_iv_inputBF.Text = Clipboard.GetText(); } } }