Beispiel #1
0
        private void ButtonEnvi1_Click(object sender, RoutedEventArgs e) // button send chat 1
        {
            if (Chat1.Text != "")
            {
                send2++;

                if (CheckBoxDecript2.IsChecked == true) // se o checkbox do Lucas estiver marcado, envia o texto normal
                {
                    TextEncrypt1 = bce.Encrypt(Chat1.Text, ChaveEncript.Text);

                    Not22.Badge     = send2;
                    FirstChat.Text += "Douglas: " + Chat1.Text + "\n";
                    Chat1.Text      = "";

                    SendText();

                    NewMessage2.Visibility = Visibility.Visible;
                    Not222.Badge           = send2;
                    TimerNot2();

                    if (PanelChat2.Visibility == Visibility.Visible)
                    {
                        Not22.Badge = "";
                    }
                }

                else // se não, envia o texto criptografado pro douglas
                {
                    if (!string.IsNullOrEmpty(ChaveEncript.Text))
                    {
                        TextEncrypt1 = bce.Encrypt(Chat1.Text, ChaveEncript.Text);

                        FirstChat.Text  += "Douglas: " + Chat1.Text + "\n";
                        TextSecond.Text += "Douglas: " + TextEncrypt1 + "\n";
                        Chat1.Text       = "";
                        Not22.Badge      = send2;
                        Not222.Badge     = send2;
                    }
                    else
                    {
                        FirstChat.Text  += "Douglas: " + Chat1.Text + "\n"; //linha que vai criptografar o texto
                        TextSecond.Text += "Douglas: " + Chat1.Text + "\n";
                        Chat1.Text       = "";
                        Not22.Badge      = send2;
                        Not222.Badge     = send2;
                    }

                    if (PanelChat2.Visibility == Visibility.Visible)
                    {
                        Not22.Badge = "";
                    }

                    NewMessage2.Visibility = Visibility.Visible;
                    Not222.Badge           = send2;
                    TimerNot2();
                }
            }
        }
Beispiel #2
0
        public string AESEncryption(string plain, string key)
        {
            BCEngine bcEngine = new BCEngine(new AesEngine(), _encoding);

            bcEngine.SetPadding(_padding);
            return(bcEngine.Encrypt(plain, key));
        }
        public static string Encrypt(string plain, string key)
        {
            BCEngine bcEngine = new BCEngine(new AesEngine(), Encoding.ASCII);

            bcEngine.SetPadding(new Pkcs7Padding());
            return(bcEngine.Encrypt(plain, key));
        }
Beispiel #4
0
        public string AESEncryption(string plain)
        {
            /*
             * SecureRandom random = new SecureRandom();
             * byte[] keyBytes = new byte[16];
             * random.NextBytes(keyBytes);
             * string key = Convert.ToBase64String(keyBytes);
             * Debug.WriteLine(key);
             */
            BCEngine bcEngine = new BCEngine(new AesEngine(), _encoding);

            bcEngine.SetPadding(_padding);
            return(bcEngine.Encrypt(plain, bc_key));
        }
        public bool Register(Trainer p_registerRequest)
        {
            try
            {
                var encrypted = BCEngine.Encrypt(p_registerRequest.Password);
                p_registerRequest.Password = encrypted;

                p_registerRequest.JoinedCompany = DateTime.Now;
                _trainerService.AddTrainer(p_registerRequest);
                p_registerRequest.Password = null;
                return(true);
            }
            catch (System.Exception ex)
            {
                throw new WebApiException(500, ex.Message);
            }
        }
Beispiel #6
0
    public AesExample()
    {
        InitializeComponent();
        string key = "b09f72a0lkb1lktb";

        string plainText = "Text To Encrypt";

        BCEngine bcEngine        = new BCEngine();
        string   encryptedString = bcEngine.Encrypt(plainText, key);

        Console.WriteLine("\n\nEncrypted String==> " + encryptedString);

        BCEngine bcEnginenew     = new BCEngine();
        string   decryptedString = bcEnginenew.Decrypt(encryptedString, key);

        Console.WriteLine("\n\nDecrypted String==> " + decryptedString);
    }