Ejemplo n.º 1
0
        private void decode_button_click(object sender, EventArgs e)
        {
            //string src = d_src_tb.Text;
            //string dst = d_dst_tb.Text;
            String password = d_password_tb.Text;
            String private_key;

            if (d_users_list.SelectedItem != null && d_src_tb.Text != "Wybierz plik" && d_dst_tb.Text != "Wybierz plik")
            {
                String selected_user = d_users_list.SelectedItem.ToString();


                IAlgorithm alg = decryptKey(private_keys_path.ToString() + selected_user, password);

                Int64 length = alg.getSrcLength();
                Int64 step   = System.Convert.ToInt64(Math.Ceiling(length / (double)100));
                Int64 bytes  = 1;

                d_status_lbl.Text = "Trwa przetwarzanie klucza prywatnego";
                while (bytes > 0)
                {
                    // "unit work" szyfrowanie fragmentu pliku
                    bytes = alg.encrypt(step);
                }
                alg.Dispose();

                d_status_lbl.Text = "Zaczeto odszyfrowanie";
                //szyfrowanie######################################## do oddzielnej funkcji decode
                private_key = get_private_key(selected_user);
                alg         = decryptFile(d_src_tb.Text, d_dst_tb.Text, password, private_key, selected_user);

                length = alg.getSrcLength();
                step   = System.Convert.ToInt64(Math.Ceiling(length / (double)100));
                bytes  = 1;

                while (bytes > 0)
                {
                    // "unit work" szyfrowanie fragmentu pliku
                    bytes = alg.encrypt(step);
                }
                alg.Dispose();

                MessageBox.Show("Odszyfrowanie zakonczone sukcesem!");
                d_status_lbl.Text = "Odszyfrowanie zakonczone";
            }
            else
            {
                MessageBox.Show("Zaznacz plik lub wybierz uzytkownika!");
            }
        }
Ejemplo n.º 2
0
        //TODO Zaszyfrowac klucz publiczny i prywatny za pomoca hasla!!!
        private void create_user(String name, String password)
        {
            String key_length_str = key_length_cb.Text;
            int    key_length     = Int32.Parse(key_length_str.Substring(0, key_length_str.IndexOf(" ")));

            RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(key_length);
            var private_key = rsa.ToXmlString(true);
            var public_key  = rsa.ToXmlString(false); // RSA.FromXmlString(publicKey);

            var SHA = SHA256.Create();

            byte[]       hashed_password = SHA.ComputeHash(GetBytes(password));
            KeyParameter session_key     = new KeyParameter(hashed_password);

            //szyfruje klucz prywatny za pomoca hasla, i skrotu funkcji SHA_256

            using (StreamWriter sw = new StreamWriter(public_keys_path + name, true))
            {
                sw.Write(public_key);
                sw.Flush();
                sw.Close();
            }
            using (StreamWriter sw = new StreamWriter(private_keys_path + name + "tmp", true))
            {
                sw.Write(private_key);
                sw.Flush();
                sw.Close();
            }

            IAlgorithm alg    = encryptFile(private_keys_path + name + "tmp", private_keys_path + name, "ECB", 128, 128, Convert.ToBase64String(hashed_password), session_key, hashed_password);
            Int64      length = alg.getSrcLength();
            Int64      step   = System.Convert.ToInt64(Math.Ceiling(length / (double)100));
            Int64      bytes  = 1;

            while (bytes > 0)
            {
                // "unit work" szyfrowanie fragmentu pliku
                bytes = alg.encrypt(step);
            }
            alg.Dispose();
            File.Delete(private_keys_path + name + "tmp");
        }
Ejemplo n.º 3
0
        private void encryptWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            //System.Console.WriteLine("encryptWorker_RunWorkerCompleted");

            restoreDefaultControlsState();

            if (!e.Cancelled)
            {
                IAlgorithm alg        = e.Result as IAlgorithm;
                bool       encryption = alg.Encryption;
                alg.Dispose();

                var opStatus = (encryption ? "зашифровано" : "расшифрованно");
                statusBarLabel.Text = opStatus;
            }
            else
            {
                statusBarLabel.Text = "прервано";
            }
        }