Beispiel #1
0
        private void EnterButton_Click(object sender, RoutedEventArgs e)
        {
            if (File.Exists(MainWindow.UserDirectoryPath + this.loginTextBox.Text + ".mcd"))
            {
                byte[] userEncryptedData = File.ReadAllBytes(MainWindow.UserDirectoryPath +
                                                             this.loginTextBox.Text + ".mcd");
                byte[] userData = Encrypter.DecryptWithAesAndRsa(userEncryptedData, Encrypter.DefaultKeyContainerName, false);
                User   user     = BinarySerializer.Deserialize <User>(userData);

                if (user.Password == this.passwordTextBox.Password)
                {
                    this.AuthUser = user;

                    if (this.remeberMeCheckBox.IsChecked == true)
                    {
                        byte[] serData    = BinarySerializer.Serialize(user.Login);
                        byte[] encSerData = Encrypter.EncryptWithAesAndRsa(serData, Encrypter.DefaultKeyContainerName, false);
                        File.WriteAllBytes(MainWindow.RememberMeDataPath, encSerData);
                    }

                    this.Close();
                }
                else
                {
                    MessageBox.Show("Неправильный пароль!", "Ошибка",
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                MessageBox.Show("Такого пользователя не существует!", "Ошибка",
                                MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Beispiel #2
0
        private void RegistrationButton_Click(object sender, RoutedEventArgs e)
        {
            RegistrationWindow registrationWindow = new RegistrationWindow()
            {
                Owner = this
            };

            registrationWindow.ShowDialog();
            this.AuthUser = registrationWindow.RegistredUser;
            if (this.AuthUser != null)
            {
                byte[] serData    = BinarySerializer.Serialize(this.AuthUser);
                byte[] encSerData = Encrypter.EncryptWithAesAndRsa(serData, Encrypter.DefaultKeyContainerName, false);
                File.WriteAllBytes(MainWindow.UserDirectoryPath + this.AuthUser.Login + ".mcd", encSerData);
                this.Close();
            }
        }
Beispiel #3
0
        private void SendButton_Click(object sender, RoutedEventArgs e)
        {
            if (this.encryptMessage.IsChecked == true &&
                this.EmailBox.XmlStringChipherKeyContainerName is null)
            {
                MessageBox.Show("Для шифрования сообщения следует импортировать открытый ключ!", "Ошибка",
                                MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (this.toTextBox.Text is null)
            {
                MessageBox.Show("Требуется ввести имя получателя.", "Ошибка",
                                MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            MailBuilder mailBuilder = new MailBuilder();

            mailBuilder.From.Add(new MailBox(this.EmailBox.EmailAddress));

            try
            {
                mailBuilder.To.Add(new MailBox(this.toTextBox.Text.Trim(' ')));
            }
            catch (ArgumentException)
            {
                MessageBox.Show("Имя получателя написано в неверном формате.", "Ошибка",
                                MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            mailBuilder.Subject = this.subjectTextBox.Text.Trim(' ');

            if (encryptMessage.IsChecked == true)
            {
                byte[] data    = this.GetBytesFromRichTextBoxText(this.textRichTextBox);
                byte[] encData = Encrypter.EncryptWithAesAndRsa(data,
                                                                this.EmailBox.XmlStringChipherKeyContainerName, true);
                byte[] signedData = Encrypter.SignData(encData,
                                                       this.EmailBox.UserKeyContainerName);
                mailBuilder.Rtf = Convert.ToBase64String(signedData);
            }
            else
            {
                mailBuilder.Rtf = this.GetTextFromRichTextBox(this.textRichTextBox);
            }

            for (int i = 0; i < this.Attachments.Count; i++)
            {
                if (encryptMessage.IsChecked == true)
                {
                    byte[] data    = this.Attachments[i];
                    byte[] encData = Encrypter.EncryptWithAesAndRsa(data,
                                                                    this.EmailBox.XmlStringChipherKeyContainerName, true);
                    byte[] signedData = Encrypter.SignData(encData,
                                                           this.EmailBox.UserKeyContainerName);

                    MimeData mime = mailBuilder.AddAttachment(signedData);
                    mime.FileName = (string)this.attachmentsListBox.Items[i];
                }
                else
                {
                    MimeData mime = mailBuilder.AddAttachment(this.Attachments[i]);
                    mime.FileName = (string)this.attachmentsListBox.Items[i];
                }
            }

            IMail mail = mailBuilder.Create();

            if (sendThread != null && sendThread.IsAlive)
            {
                sendThread.Abort();
                sendThread.Join();
            }

            sendThread = new Thread(() =>
            {
                this.Dispatcher.Invoke(() =>
                {
                    this.sendButton.IsEnabled = false;
                    Mouse.OverrideCursor      = Cursors.AppStarting;
                });

                this.EmailBox.Smtp.SendMessage(mail);

                this.Dispatcher.Invoke(() =>
                {
                    this.Close();
                    this.sendButton.IsEnabled = true;
                    Mouse.OverrideCursor      = null;
                });
            });
            sendThread.Start();
        }
Beispiel #4
0
 private void EncryptAndSerializeCurrentUser()
 {
     byte[] serData    = BinarySerializer.Serialize(this.CurrentUser);
     byte[] encSerData = Encrypter.EncryptWithAesAndRsa(serData, Encrypter.DefaultKeyContainerName, false);
     File.WriteAllBytes(MainWindow.UserDirectoryPath + this.CurrentUser.Login + ".mcd", encSerData);
 }