Kashub's Code Barn - "gvvnvb"

podświetlone jako text (dodał(a) hbgbhb @ 2022-12-13 18:47:02)

Twoja wyszukiwarka
T-Mobile
Podświetl ten kod w:
Ostatnio dodane:
Losowe wpisy:
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();
        }
    }
}
 
| Sklepy internetowe | | Sklep z artykułami dla dzieci | | karma dla psa - sklep | | Programista Trójmiasto | | Skracacz linków | | Blogi za darmo | | Kody programów | | Opisy GG | | Pionowe opisy |