public void ExecuteSave(object o) { // User needs to input all fields if (String.IsNullOrEmpty(Name) || String.IsNullOrEmpty(Website) || String.IsNullOrEmpty(Username) || String.IsNullOrEmpty(Password)) { return; } byte[] masterKey = CryptoUtil.MasterKey; byte[] passwordBytes = ASCIIEncoding.ASCII.GetBytes(this.Password); // Convert the encrypted password to a base64 string for storage string passwordToStore = Convert.ToBase64String(CryptoUtil.AES_GCMEncrypt(passwordBytes, masterKey)); // TODO: Check if password contains non-base64 chars PasswordModel newPassword = new PasswordModel() { Name = this.Name, Website = this.Website, Username = this.Username, Password = passwordToStore }; // Places the new PasswordModel into the database with the encrypted password SQLiteDataAccess.SavePassword(newPassword); // TODO: Place this password into a secure string // Sets password for the bindable collection to the decrypted version newPassword.Password = this.Password; VaultVM.Passwords.Add(newPassword); // After saving, goes back to the basic display view of the selected password VaultVM.PassScreenType = new DisplayPasswordViewModel(SelectedPassword, VaultVM); }
public void ExecuteCreateUser(object o) { string newUserPassword = null; string newUserConfirmPassword = null; if (SecurePassword != null & SecureConfirmPassword != null) { newUserPassword = SecurePassword.GetString(); newUserConfirmPassword = SecureConfirmPassword.GetString(); } // Checks to see if input fields are empty or null if (String.IsNullOrEmpty(Username) || String.IsNullOrEmpty(newUserPassword) || String.IsNullOrEmpty(newUserConfirmPassword)) { CredentialStatus = "Please input all fields"; return; } // Check if user already exists in database if (SQLiteDataAccess.DoesUserExist(Username)) { CredentialStatus = "User already exists"; return; } // Checks to see if both passwords match before creating a new user if (newUserPassword == newUserConfirmPassword) { byte[] masterKey = CryptoUtil.GenerateByteArray(32); byte[] salt = CryptoUtil.GenerateByteArray(32); // Creates the Key Encryption Key derived from the master password using PBKDF2-SHA256 byte[] keyEncryptionKey = CryptoUtil.ComputePBKDF2Hash(newUserPassword, salt); // Encrypts the master key using the Key Encryption Key and converts it to a base64 string for storage string encryptedMasterKey = Convert.ToBase64String(CryptoUtil.AES_GCMEncrypt(masterKey, keyEncryptionKey)); Console.WriteLine($"{Username} - Master Key: {Convert.ToBase64String(masterKey)}"); Console.WriteLine($"{Username} - Key Encryption Key: {Convert.ToBase64String(keyEncryptionKey)}"); Console.WriteLine($"{Username} - Encrypted Master Key: {encryptedMasterKey}"); UserModel newUser = new UserModel { Username = Username, Password = encryptedMasterKey, Salt = Convert.ToBase64String(salt) }; SQLiteDataAccess.CreateUser(newUser); var parentConductor = this.Parent as Conductor <Screen>; parentConductor.ActivateItem(new LoginViewModel()); } else { CredentialStatus = "Passwords do not match"; } }
private void ExecuteEncrypt(object o) { if (!String.IsNullOrEmpty(Password)) { byte[] passwordBytes = ASCIIEncoding.ASCII.GetBytes(Password); byte[] masterKey = CryptoUtil.MasterKey; string encryptedPassword = Convert.ToBase64String(CryptoUtil.AES_GCMEncrypt(passwordBytes, masterKey)); Cipher = encryptedPassword; } else { Cipher = ""; } }
public void ExecuteSave(object o) { VaultVM.SelectedPasswordModel.Name = this.Name; VaultVM.SelectedPasswordModel.Website = this.Website; VaultVM.SelectedPasswordModel.Username = this.Username; // Encrypts and stores the password in the database byte[] passwordBytes = ASCIIEncoding.ASCII.GetBytes(this.Password); byte[] masterKey = CryptoUtil.MasterKey; byte[] encryptedPassword = CryptoUtil.AES_GCMEncrypt(passwordBytes, masterKey); VaultVM.SelectedPasswordModel.Password = Convert.ToBase64String(encryptedPassword); SQLiteDataAccess.UpdatePassword(VaultVM.SelectedPasswordModel); // Updates password in bindable collection VaultVM.SelectedPasswordModel.Password = this.Password; VaultVM.PassScreenType = new DisplayPasswordViewModel(SelectedPassword, VaultVM); }