コード例 #1
0
        private void GenerateRandomKeyButton_Click(object sender, EventArgs e)
        {
            if (EncryptButton.Text == "Stop")
            {
                foreach (Encryptor f in arr)
                {
                    f.Stop();
                    EncryptButton.Text = "Encrypt";
                    arr.Remove(f);
                }
            }
            else
            {
                Encryptor E = null;



                //AES
                if (encryptionMethodComboBox.SelectedIndex == 0)
                {
                    if (RandomKeyCheckBox.Checked)
                    {
                        //start with random generated key
                        E = new AES();
                        MessageBox.Show("Made E 2");
                    }
                    else
                    {
                        //start with user input key
                        if (encryptionKeyTextbox.Text.Length >= 128 && (encryptionKeyTextbox.Text.Length % 32) == 0)
                        {
                            E = new AES(encryptionKeyTextbox.Text);
                            MessageBox.Show("Made E");
                        }
                        else
                        {
                            MessageBox.Show("Key length must be greater than 128 and a multiple of 32");
                        }
                    }
                    //if encrypt radio ticked to determine if encryption or decryption
                    //E.Start(encryptRadioButton.Checked);
                    if (E != null)
                    {
                        E.Start(encryptRadioButton.Checked);
                        EncryptButton.Text = "Stop";
                        arr.Add(E);

                        while (!E.complete)
                        {
                            //wait for the asynchronous process to finish, signalled by E.complete being set;
                        }

                        //when e.complete = true
                        E.Output(ref ciphertextTextbox);
                    }
                }
                //RSA
                if (encryptionMethodComboBox.SelectedIndex == 1)
                {
                    MessageBox.Show("Being developed soon!");
                }
                //TripleDes
                if (encryptionMethodComboBox.SelectedIndex == 2)
                {
                    MessageBox.Show("Being developed soon!");
                }
                //Blowfish
                if (encryptionMethodComboBox.SelectedIndex == 3)
                {
                    MessageBox.Show("Being developed soon!");
                }
                //TwoFish
                if (encryptionMethodComboBox.SelectedIndex == 4)
                {
                    MessageBox.Show("Being developed soon!");
                }
            }
        }
コード例 #2
0
        private void GenerateRandomKeyButton_Click(object sender, EventArgs e)
        {
            if (EncryptButton.Text == "Stop")
            {
                foreach (Encryptor f in arr)
                {
                    f.Stop();
                    EncryptButton.Text = "Encrypt";
                    arr.Remove(f);
                }
            }
            else
            {
                Encryptor E = null;

                EncryptionType Type = EncryptionType.None;
                Type = (EncryptionType)Enum.Parse(typeof(EncryptionType), encryptionMethodComboBox.Text, true);

                //AES
                if (Type == EncryptionType.AES)
                {
                    if (RandomKeyCheckBox.Checked)
                    {
                        //start with random generated key
                        E = new AES();
                    }
                    else
                    {
                        //start with user input key
                        E = new AES(encryptionKeyTextbox.Text);
                        //check that the new key is accepted by AES
                    }
                    if (!E.ValidateKey())
                    {
                        MessageBox.Show("Key length must be greater than 128 and a multiple of 32");
                        E = null;
                    }
                }

                //RSA
                if (Type == EncryptionType.RSA)
                {
                    MessageBox.Show("Being developed soon!");
                }
                //TripleDes
                if (Type == EncryptionType.TripleDES)
                {
                    MessageBox.Show("Being developed soon!");
                }
                //Blowfish
                if (Type == EncryptionType.Blowfish)
                {
                    MessageBox.Show("Being developed soon!");
                }
                //TwoFish
                if (Type == EncryptionType.Twofish)
                {
                    MessageBox.Show("Being developed soon!");
                }


                if (E != null)
                {
                    E.Start(encryptRadioButton.Checked);
                    EncryptButton.Text = "Stop";
                    arr.Add(E);


                    //when e.complete = true
                    E.Output(ref ciphertextTextbox);
                }
            }
        }