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(); } } }