/// <summary>
        /// TODO: Comment
        /// </summary>
        public void SaveConfigurationExcecute()
        {
            string configurationPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                "SecureVault",
                "settings",
                "configuration.dat");

            ConfigurationHelper configHelper = new ConfigurationHelper(configurationPath);
            HashHelper hashHelper = new HashHelper();
            SecureStringHelper secureStringHelper = new SecureStringHelper();

            if (String.IsNullOrWhiteSpace(secureStringHelper.SecureStringToString(this.MasterPassword)) ||
                String.IsNullOrWhiteSpace(secureStringHelper.SecureStringToString(this.MasterPasswordConfirmation)))
            {
                this.Error = "Please set a Password";
                return;
            }

            //Check if password and confirmation are equal
            if (secureStringHelper.SecureStringToString(this.MasterPassword).Equals(secureStringHelper.SecureStringToString(this.MasterPasswordConfirmation)))
            {
                //Create configuration file
                configHelper.CreateConfigurationFile();

                //Save master password
                string passwordHash = hashHelper.ComputeHash(secureStringHelper.SecureStringToString(this.MasterPassword));
                configHelper.SaveMasterPassword(passwordHash);

                //Navigate to PasswordPage
                PasswordPage passwordPage = new PasswordPage();
                passwordPage.DataContext = new PasswordViewModel(new Vault(), this.MainFrame);

                this.MainFrame.Navigate(passwordPage);
            }
            else
            {
                this.Error = "Not equal";
            }
        }
        /// <summary>
        /// TODO: Comment
        /// </summary>
        public void AuthenticateExcecute()
        {
            //TODO: Save path in configuration
            string configurationPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                "SecureVault",
                "settings",
                "configuration.dat");

            ConfigurationHelper configHelper = new ConfigurationHelper(configurationPath);
            HashHelper hashHelper = new HashHelper();
            SecureStringHelper secureStringHelper = new SecureStringHelper();

            //Check if password is correct
            if (hashHelper.ComputeHash(secureStringHelper.SecureStringToString(this.Password)).Equals(configHelper.GetPasswordHash()))
            {
                IEnumerable<Tuple<string, string, string>> savedData = configHelper.GetAllSavedData();
                ObservableCollection<SavedData> dataCollection = new ObservableCollection<SavedData>();

                foreach (var data in savedData)
                {
                    dataCollection.Add(new SavedData() { Name = data.Item1, EncryptedValue = data.Item2, Salt = data.Item3 });
                }

                this.Model.SavedData = dataCollection;

                //Navigate to the VaultPage
                VaultPage vaultPage = new VaultPage();
                vaultPage.DataContext = new VaultViewModel(this.Model);
                this.MainFrame.Navigate(vaultPage);
            }
            else
            {
                this.Error = "Invalid Password";
                this.Model.SavedData = null;
            }
        }
예제 #3
0
        /// <summary>
        /// TODO: Comment
        /// </summary>
        public void ShowPasswordExcecute(int? selectedID)
        {
            //TODO: Save path in configuration
            string configurationPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                "SecureVault",
                "settings",
                "configuration.dat");

            ConfigurationHelper configHelper = new ConfigurationHelper(configurationPath);
            KeyHelper keyHelper = new KeyHelper();
            SecureStringHelper secureStringHelper = new SecureStringHelper();

            byte[] key = keyHelper.DeriveKey(secureStringHelper.SecureStringToString(this.Password), configHelper.GetSalt());

            CryptoHelper cryptoHelper = new CryptoHelper(key, Convert.FromBase64String(this.SavedData[selectedID.Value].Salt));

            string decryptedValue = cryptoHelper.DecryptValue(this.SavedData[selectedID.Value].EncryptedValue);

            this.DecryptedPassword = decryptedValue;
        }
        /// <summary>
        /// TODO: Comment
        /// </summary>
        public void SaveDataExcecute()
        {
            //TODO: Save path in configuration
            string configurationPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                "SecureVault",
                "settings",
                "configuration.dat");

            ConfigurationHelper configHelper = new ConfigurationHelper(configurationPath);
            SecureStringHelper secureStringHelper = new SecureStringHelper();
            KeyHelper keyHelper = new KeyHelper();
            SaltGenerator saltGenerator = new SaltGenerator();

            //Generate random salt
            byte[] salt = saltGenerator.GenerateSalt();

            byte[] key = keyHelper.DeriveKey(secureStringHelper.SecureStringToString(this.Password), configHelper.GetSalt());

            CryptoHelper cryptoHelper = new CryptoHelper(key, salt);

            var plainTextBytes = Encoding.UTF8.GetBytes(secureStringHelper.SecureStringToString(this.SecureData));
            var plainPasswordBase64 = Convert.ToBase64String(plainTextBytes);

            string encryptedValue = cryptoHelper.EncryptValue(plainPasswordBase64);

            configHelper.AddData(this.Name, encryptedValue, Convert.ToBase64String(salt));

            //Close the NewData window
            Application.Current.Windows.OfType<Window>().SingleOrDefault(x => x.IsActive).Close();
        }