Exemplo n.º 1
0
        /// <summary>
        /// Descriptação do relatório.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_descriptar_relatorio_Click(object sender, EventArgs e)
        {
            // Chave-privada não informada.
            if (chave_privada_relatorio.Text.Equals(""))
            {
                var retornos = msg.Retorno_Erro_Processo(cumi.Check_Idioma_Internacional(), 12, 1);
                MessageBox.Show(retornos.Item1, retornos.Item2, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                if (cumi.Check_Status() == true)
                {
                    try
                    {
                        cumi.Pensar_Fala(2, 12);
                    }

                    catch
                    {
                        cumi.Pensar_Fala(2, 16);
                        var retornos1 = msg.Retorno_Erro_Processo(cumi.Check_Idioma_Internacional(), 16, 3);
                        MessageBox.Show(retornos1.Item1, retornos1.Item2, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }

            // Chave-privada informada.
            else
            {
                try
                {
                    RSA_Processo criptacao_titulo    = new RSA_Processo();
                    RSA_Processo criptacao_data      = new RSA_Processo();
                    RSA_Processo criptacao_descricao = new RSA_Processo();

                    titulo.Text = criptacao_titulo.Decriptacao(titulo.Text, false, Convert.ToInt32(chave_privada_relatorio.Text), (int)Chaves_Padronizadas.MISTA);
                    data.Text   = criptacao_data.Decriptacao(data.Text, false, Convert.ToInt32(chave_privada_relatorio.Text), (int)Chaves_Padronizadas.MISTA);
                    relatorio_descricao.Text = criptacao_descricao.Decriptacao(relatorio_descricao.Text, false, Convert.ToInt32(chave_privada_relatorio.Text), (int)Chaves_Padronizadas.MISTA);
                }
                catch
                {
                    relatorio_descricao.Text = "X??????X"; //exemplo disso ocorrer: quando um caractere-letra é passado como chave.
                }
                finally
                {
                    flowLayoutPanel1.AutoScroll = false;
                }
            }

            chave_privada_relatorio.Text = "";
        }
Exemplo n.º 2
0
        /// <summary>
        /// Descriptação da mensagem.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_descriptar_Click(object sender, EventArgs e)
        {
            // Caso algum input não tenha sido informado
            if ((chave_privada.Text.Equals("")) || (chave_mista.Text.Equals("")) || (msg_encriptada_de.Text.Equals("")))
            {
                // Caso a mensagem, a chave-mista e a privada não tenham sido informadas
                if ((chave_privada.Text.Equals("")) && (chave_mista.Text.Equals("")) && (msg_encriptada_de.Text.Equals("")))
                {
                    var retornos = msg.Retorno_Erro_Processo(cumi.Check_Idioma_Internacional(), 4, 1);
                    MessageBox.Show(retornos.Item1, retornos.Item2, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                    if (cumi.Check_Status() == true)
                    {
                        try
                        {
                            cumi.Pensar_Fala(2, 4);
                        }

                        catch
                        {
                            cumi.Pensar_Fala(2, 16);
                            var retornos1 = msg.Retorno_Erro_Processo(cumi.Check_Idioma_Internacional(), 16, 3);
                            MessageBox.Show(retornos1.Item1, retornos1.Item2, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }

                // Caso uma das três não tenha sido informada
                else if ((chave_privada.Text.Equals("")) ^ (chave_mista.Text.Equals("")) ^ (msg_encriptada_de.Text.Equals("")))
                {
                    /* Chave-Privada */
                    if (chave_privada.Text.Equals(""))
                    {
                        var retornos = msg.Retorno_Erro_Processo(cumi.Check_Idioma_Internacional(), 12, 1);
                        MessageBox.Show(retornos.Item1, retornos.Item2, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                        if (cumi.Check_Status() == true)
                        {
                            try
                            {
                                cumi.Pensar_Fala(2, 12);
                            }

                            catch
                            {
                                cumi.Pensar_Fala(2, 16);
                                var retornos1 = msg.Retorno_Erro_Processo(cumi.Check_Idioma_Internacional(), 16, 3);
                                MessageBox.Show(retornos1.Item1, retornos1.Item2, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                    }

                    /* Chave-Mista */
                    else if (chave_mista.Text.Equals(""))
                    {
                        var retornos = msg.Retorno_Erro_Processo(cumi.Check_Idioma_Internacional(), 10, 1);
                        MessageBox.Show(retornos.Item1, retornos.Item2, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                        if (cumi.Check_Status() == true)
                        {
                            try
                            {
                                cumi.Pensar_Fala(2, 10);
                            }

                            catch
                            {
                                cumi.Pensar_Fala(2, 16);
                                var retornos1 = msg.Retorno_Erro_Processo(cumi.Check_Idioma_Internacional(), 16, 3);
                                MessageBox.Show(retornos1.Item1, retornos1.Item2, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                    }

                    /* Mensagem Encriptada */
                    else
                    {
                        var retornos = msg.Retorno_Erro_Processo(cumi.Check_Idioma_Internacional(), 17, 1);
                        MessageBox.Show(retornos.Item1, retornos.Item2, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                        if (cumi.Check_Status() == true)
                        {
                            try
                            {
                                cumi.Pensar_Fala(2, 17);
                            }

                            catch
                            {
                                cumi.Pensar_Fala(2, 16);
                                var retornos1 = msg.Retorno_Erro_Processo(cumi.Check_Idioma_Internacional(), 16, 3);
                                MessageBox.Show(retornos1.Item1, retornos1.Item2, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                    }
                }

                // Caso duas delas não tenham sido informadas
                else
                {
                    /* Chave-Mista e Privada */
                    if (chave_mista.Text.Equals("") && chave_privada.Text.Equals(""))
                    {
                        var retornos = msg.Retorno_Erro_Processo(cumi.Check_Idioma_Internacional(), 9, 1);
                        MessageBox.Show(retornos.Item1, retornos.Item2, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                        if (cumi.Check_Status() == true)
                        {
                            try
                            {
                                cumi.Pensar_Fala(2, 9);
                            }

                            catch
                            {
                                cumi.Pensar_Fala(2, 16);
                                var retornos1 = msg.Retorno_Erro_Processo(cumi.Check_Idioma_Internacional(), 16, 3);
                                MessageBox.Show(retornos1.Item1, retornos1.Item2, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                    }

                    /* Chave-Mista e Mensagem Encriptada */
                    else if (chave_mista.Text.Equals("") && msg_encriptada_de.Text.Equals(""))
                    {
                        var retornos = msg.Retorno_Erro_Processo(cumi.Check_Idioma_Internacional(), 5, 1);
                        MessageBox.Show(retornos.Item1, retornos.Item2, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                        if (cumi.Check_Status() == true)
                        {
                            try
                            {
                                cumi.Pensar_Fala(2, 5);
                            }

                            catch
                            {
                                cumi.Pensar_Fala(2, 16);
                                var retornos1 = msg.Retorno_Erro_Processo(cumi.Check_Idioma_Internacional(), 16, 3);
                                MessageBox.Show(retornos1.Item1, retornos1.Item2, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                    }

                    /* Chave-Privada e Mensagem Encriptada */
                    else if (chave_privada.Text.Equals("") && msg_encriptada_de.Text.Equals(""))
                    {
                        var retornos = msg.Retorno_Erro_Processo(cumi.Check_Idioma_Internacional(), 7, 1);
                        MessageBox.Show(retornos.Item1, retornos.Item2, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                        if (cumi.Check_Status() == true)
                        {
                            try
                            {
                                cumi.Pensar_Fala(2, 7);
                            }

                            catch
                            {
                                cumi.Pensar_Fala(2, 16);
                                var retornos1 = msg.Retorno_Erro_Processo(cumi.Check_Idioma_Internacional(), 16, 3);
                                MessageBox.Show(retornos1.Item1, retornos1.Item2, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                    }
                }
            }

            // Caso ambas sejam informadas, ocorre a descriptação.
            else
            {
                // Tentativa de decriptação
                try
                {
                    int          Chave_Privada            = 0;
                    RSA_Processo criptacao_msg_encriptada = new RSA_Processo();
                    // Tentativa de atribuição de valor na variávbel "Chave_Privada"
                    // Dois possíveis erros são:
                    // 1 → Nenhum primo informado nas textbox's correspondentes;
                    // 2 → Dado impossível de ser convertido para Int32 nas textbox's correspondentes.
                    try
                    {
                        Chave_Privada = (check_valor_negativo.Checked) ? criptacao_msg_encriptada.Chave_Privada_Negativa(Convert.ToInt32(primo1.Text), Convert.ToInt32(primo2.Text), Convert.ToInt32(chave_privada.Text)) : Convert.ToInt32(chave_privada.Text);
                    }

                    catch
                    {
                        if (primo1.Text.Equals("") || primo2.Text.Equals(""))
                        {
                            var retornos1 = msg.Retorno_Erro_Processo(cumi.Check_Idioma_Internacional(), 20, 0);
                            MessageBox.Show(retornos1.Item1, retornos1.Item2, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        }

                        else
                        {
                            var retornos2 = msg.Retorno_Erro_Processo(cumi.Check_Idioma_Internacional(), 21, 5);
                            MessageBox.Show(retornos2.Item1, retornos2.Item2, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        }
                    }

                    msg_descriptada_de.Text = criptacao_msg_encriptada.Decriptacao(msg_encriptada_de.Text, false, Chave_Privada, Convert.ToInt32(chave_mista.Text));
                }

                catch
                {
                    msg_descriptada_de.Text = "X??????X"; // exemplo disso ocorrer: um caractere-letra passado como chave.
                }
            }
        }