Esempio n. 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (ValidateFields())
            {
                try
                {
                    lblErrorMessage.Visible = false;

                    var clearText = Encoding.UTF8.GetBytes(txtInput.Text);

                    // Get the key
                    var key = Encoding.UTF8.GetBytes(txtKey.Text); //Rijndael.Create().Key;

                    byte[] cipherText = AesImplementation.Encrypt(clearText, key);

                    txtOutput.Text = Convert.ToBase64String(cipherText);

                    txtHexOutput.Text = BitConverter.ToString(cipherText);
                }
                catch (Exception exception)
                {
                    MessageBox.Show($@"An error occured: {exception}");
                }
            }
        }
Esempio n. 2
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (ValidateFields())
            {
                try
                {
                    lblErrorMessage.Visible = false;

                    byte[] cipherText = Convert.FromBase64String(txtInput.Text);

                    // Get the key
                    var key = Encoding.UTF8.GetBytes(txtKey.Text);

                    // Decrypt the cipher text
                    byte[] plainText = AesImplementation.Decrypt(cipherText, key);

                    // Set the right output
                    txtOutput.Text    = Encoding.UTF8.GetString(plainText);
                    txtHexOutput.Text = BitConverter.ToString(plainText);
                }
                catch (Exception exception)
                {
                    MessageBox.Show($@"An error occured: {exception}");
                }
            }
        }
Esempio n. 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            var clearText = Encoding.UTF8.GetBytes(txtInput.Text);

            // Hard coded key
            var key = Encoding.UTF8.GetBytes("1a25s8fe5dsg65ad"); //Rijndael.Create().Key;

            byte[] cipherText = AesImplementation.Encrypt(clearText, key);

            string finalTeksti = Encoding.UTF8.GetString(cipherText);

            txtOutput.Text = finalTeksti;

            var someresult = AesImplementation.Decrypt(cipherText, key);

            txtHexOutput.Text = Encoding.UTF8.GetString(someresult);

            //            if (ValidateFields())
            //            {
            //                try
            //                {
            //                    lblValidateTekstin.Visible = false;
            //                    var enkriptim = radioEncrypt.Checked;
            //                    var rezultati = enkriptim
            //                        ? AesAlgorithm.EncryptString(txtTekstiHyres.Text, txtCelesi.Text)
            //                        : AesAlgorithm.DecryptString(txtTekstiHyres.Text, txtCelesi.Text);
            //
            //                    txtDalja.Text = rezultati;
            //                    var bajtat = enkriptim
            //                  ? Convert.FromBase64String(rezultati)
            //                  : Encoding.UTF8.GetBytes(rezultati);
            //                    RezultatiHex.Text = BitConverter.ToString(bajtat);
            //                }
            //                catch (Exception ex)
            //                {
            //                    txtDalja.Text = "Gabim " + ex.ToString();
            //                }
            //            }
        }