示例#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);
            }
        }
示例#2
0
        private void UserDataReading()
        {
            if (!Directory.Exists(MainWindow.UserDirectoryPath))
            {
                Directory.CreateDirectory(MainWindow.UserDirectoryPath);
            }

            if (File.Exists(MainWindow.RememberMeDataPath))
            {
                byte[] encryptedRememberMeData = File.ReadAllBytes(MainWindow.RememberMeDataPath);
                byte[] rememberMeData          = Encrypter.DecryptWithAesAndRsa(encryptedRememberMeData, Encrypter.DefaultKeyContainerName, false);
                string rememberMeLogin         = BinarySerializer.Deserialize <string>(rememberMeData);

                if (File.Exists(MainWindow.UserDirectoryPath + rememberMeLogin + ".mcd"))
                {
                    byte[] encryptedUserData = File.ReadAllBytes(MainWindow.UserDirectoryPath + rememberMeLogin + ".mcd");
                    byte[] userData          = Encrypter.DecryptWithAesAndRsa(encryptedUserData, Encrypter.DefaultKeyContainerName, false);
                    this.CurrentUser = BinarySerializer.Deserialize <User>(userData);
                }
                else
                {
                    File.Delete(MainWindow.RememberMeDataPath);
                }
            }
            else
            {
                AuthWindow authWindow = new AuthWindow()
                {
                    Owner = this
                };
                authWindow.ShowDialog();
                this.CurrentUser = authWindow.AuthUser;
            }
        }
示例#3
0
        private byte[] TryDecryptData(byte[] data)
        {
            bool signTrue = false;

            try
            {
                signTrue = Encrypter.CheckSign(data, this.EmailBox.XmlStringSignKeyContainerName);
            }
            catch (Exception)
            {
                MessageBox.Show("Подпись данных повреждена или отсутствует!", "Ошибка",
                                MessageBoxButton.OK, MessageBoxImage.Error);
                return(data);
            }

            if (!signTrue)
            {
                MessageBox.Show("Подпись файла не совпадает!", "Ошибка",
                                MessageBoxButton.OK, MessageBoxImage.Error);
                return(data);
            }

            byte[] decData;

            try
            {
                byte[] encData = Encrypter.ReturnDataWithoutHash(data);
                decData = Encrypter.DecryptWithAesAndRsa(encData, this.EmailBox.UserKeyContainerName, false);
            }
            catch (Exception)
            {
                MessageBox.Show("Данные повреждены!", "Ошибка",
                                MessageBoxButton.OK, MessageBoxImage.Error);
                return(data);
            }

            return(decData);
        }