Esempio n. 1
0
        //Método de evento para o clique no botão "Descriptografar"
        private void Decrypt_Click(object sender, EventArgs e)
        {
            this.Encrypt.Enabled = true;
            control = true;
            //Verifica se a caixa do texto cifrado não está vazia
            if (cipher.Length != 0)
            {
                //O texto descriptografado é enviado para uma string
                string plain = AES.Decrypt(cipher, key, iv);

                //A caixa de texto recebe o texto descriptografado que está na string
                CipherText.Text = plain;

                //Desativa o botão "Descriptografar"
                this.Decrypt.Enabled = false;
            }
            else
            {
                MessageBox.Show("criptografe algo para poder descriptografar!", "Caixa de texto vazia!",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                CipherText.Clear();
                plain_text.Clear();

                plain_text.Focus();
            }
        }
Esempio n. 2
0
        private void Clear_Click(object sender, EventArgs e)
        {
            HashText.Clear();
            PlainText.Clear();
            CipherText.Clear();

            PlainText.Focus();

            this.Encryption.Enabled = true;
        }
Esempio n. 3
0
        private void Decrypt_Click(object sender, EventArgs e)
        {
            CipherText.Clear();

            this.Decrypt.Enabled    = false;
            this.Encryption.Enabled = true;

            UnicodeEncoding code = new UnicodeEncoding();

            CipherText.Text += code.GetString(enc);
        }
Esempio n. 4
0
        //Método de evento para o clique no botão "Limpar"
        private void Clear_Click(object sender, EventArgs e)
        {
            //Limpa todas as caixas de texto
            CipherText.Clear();
            plain_text.Clear();
            TextHash.Clear();

            //Foca o mouse na primeira caixa
            plain_text.Focus();

            this.Encrypt.Enabled = true;
        }
Esempio n. 5
0
        //Método de evento para o clique no botão "Criptografar"
        private void Encrypt_Click(object sender, EventArgs e)
        {
            //Intância para escrever em um arquivo
            StreamWriter w;

            //Recebe o que foi digitado na caixa de texto
            string text = plain_text.Text;

            control = false;
            //Limpa as caixas
            CipherText.Clear();
            TextHash.Clear();
            this.Encrypt.Enabled = false;

            //Verifica se a caixa de texto foi preenchida e se está preenhcida só com caracteres de espaço
            if (!String.IsNullOrEmpty(text) && !String.IsNullOrWhiteSpace(text))
            {
                //Inicia uma instância do AES
                using (Aes AES256 = Aes.Create())
                {
                    //Abre ou cria um arquivo com o nome e extensão passados
                    using (w = File.AppendText("Crypto.txt"))
                    {
                        //Tamanho da chave criptográfica em bits
                        AES256.KeySize = 256;

                        //Envia chave e IV para as variaveis globais
                        key = AES256.Key;
                        iv  = AES256.IV;

                        //Envia o texto cifrado para o array de bytes global
                        cipher = AES.Encrypt(text, key, iv);

                        if (cipher == null)
                        {
                            this.Encrypt.Enabled = true;
                        }
                        //Percorre todo o texto cifrado
                        //Envia cada caractere cifrado para a caixa de texto em Hexadecimal
                        for (int i = 0; i < cipher.Length; i++)
                        {
                            CipherText.Text += cipher[i].ToString("X2") + " ";
                        }

                        //Desativa o botão "Descriptografar"
                        this.Decrypt.Enabled = true;

                        //Realiza o HASH e o envia para a caixa de texto do HASH em maiúsculo
                        TextHash.Text = AES.HashSHA256(plain_text.Text).ToUpper();

                        //Escreve o texto cifrado e o Hash no arquivo
                        w.WriteLine("Texto cifrado: " + CipherText.Text);
                        w.WriteLine("");
                        w.WriteLine("Hash do texto claro: " + TextHash.Text);
                        w.WriteLine("==================================================================================================\n");

                        //Fecha o arquivo
                        w.Close();
                    }


                    AES256.Dispose();
                }
            }
            else
            {
                //Em caso de dados incorretos, apresenta uma mensagem, limpa as caixas
                //e coloca o mouse na primeira caixa de texto
                MessageBox.Show("Digite algo para criptografar!", "Caixa de texto vazia!",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                CipherText.Clear();
                plain_text.Clear();
                TextHash.Clear();

                plain_text.Focus();

                this.Encrypt.Enabled = true;
            }
        }
Esempio n. 6
0
 private void ClearAll_Click(object sender, EventArgs e)
 {
     KeyText.Clear();
     PlainText.Clear();
     CipherText.Clear();
 }
Esempio n. 7
0
 private void ClearCipher_Click(object sender, EventArgs e)
 {
     CipherText.Clear();
 }