public Masterkey(byte[] keyBytes) { var encryptedKey = CryptMemoryProtection.EncryptInMemoryData(keyBytes); Value = encryptedKey; encryptedKey = null; }
/// <summary> /// Takes a byte array and stores it savely in the <see cref="_secureDatacache"/> /// </summary> internal void AddToSecureMemoryDC(Guid foreignKey, byte[] modelBytes) { CheckDatacache(); var encrpytedBytes = CryptMemoryProtection.EncryptInMemoryData(modelBytes); modelBytes = null; _secureDatacache.Add(foreignKey, encrpytedBytes); }
/// <summary> /// Returns the model with the given foreignKey from the secureDatacache /// </summary> /// <typeparam name="T"></typeparam> /// <param name="foreignKey"></param> /// <returns></returns> internal bool TryGetSensible <T>(Guid foreignKey, out T model) { CheckDatacache(); if (_secureDatacache.TryGetValue(foreignKey, out var encryptedBytes)) { var decryptedBytes = CryptMemoryProtection.DecryptInMemoryData(encryptedBytes); model = (T)ByteHelper.ByteArrayToObject(decryptedBytes); return(true); } model = (T) new object(); return(false); }
/// <summary> /// Visualises a leafList to a printablePasswordEntity-List /// </summary> /// <param name="allLeafVms"></param> public void StartPasswordEntriesPrintProcess(HashSet <LeafViewModel> allLeafVms) { try { foreach (var leafVm in allLeafVms) { if (DataAccessService.Instance.TryGetSensible <LeafPassword>(leafVm.Id, out var leafPw)) { var pw = string.Empty; if (leafPw.Value != null) { pw = ByteHelper.ByteArrayToString(leafPw.Value); } else { pw = ByteHelper.ByteArrayToString(CryptMemoryProtection.DecryptInMemoryData(leafPw.EncryptedValue)); } // Get the parent model var tuples = new Tuple <string, object>[] { Tuple.Create("Id", (object)leafVm.BranchId) }; var parent = DataAccessService.Instance.GetExplicit <Branch>(tuples).FirstOrDefault(); if (parent != default) { var printableVm = new PrintablePasswordEntryViewModel(leafVm.Name, parent.Name, leafVm.Username, pw); PrintablePasswordEntries.Add(printableVm); } pw = null; leafPw = null; } } Print(); } catch (Exception ex) { ex.SetUserMessage($"Couldn't print the requested document."); Communication.InformUserAboutError(ex); Logger.log.Error($"Error while trying to print emergency sheet: {ex}"); } }
private void Apply_Button_Click(object sender, RoutedEventArgs e) { // If the pw hasnt been changed, return false. if (_pwAtStart == Password_Textbox.Text) { Password_Textbox.Text = string.Empty; _pwAtStart = string.Empty; DialogResult = false; return; } else if (Password_Textbox.Text == string.Empty) { Information_Textblock.Text = "An empty password is not an option."; return; } // A bit ugly to put 3 methods into each other, but I want to avoid creating many extra variables when handling sensible data. ChangedPasswordEncrypted = CryptMemoryProtection.EncryptInMemoryData(ByteHelper.StringToByteArray(Password_Textbox.Text)); Password_Textbox.Text = string.Empty; _pwAtStart = string.Empty; DialogResult = true; }
/// <summary> /// Stores a serializible model into the datacache /// </summary> /// <typeparam name="T"></typeparam> /// <param name="model"></param> internal void StoreOne(ModelBase model, bool isByteModel = false, ByteModel byteModel = null) { CheckDatacache(); // If its a normal ModelBase storing. if (!isByteModel) { var ds = new DataContractSerializer(model.GetType()); var settings = new XmlWriterSettings { Indent = true }; var currentSaveLocation = Path.Combine(_databasePath, TermHelper.GetDatabaseTerm(), model.GetType().Name); // Always check if a directory exists. If not, create it. IOPathHelper.CreateDirectory(currentSaveLocation); using (var sww = new StringWriter()) { using (var w = XmlWriter.Create(Path.Combine(currentSaveLocation, $"{model.Id}.xml"), settings)) { ds.WriteObject(w, model); } } } else if (isByteModel) // If it's a byteModel { var currentSaveLocation = Path.Combine(_databasePath, TermHelper.GetDatabaseTerm(), byteModel.GetType().Name); // It's important to write the bytes decrypted since MemProtection works with the localUser. So the data would be bound to this pc and user. var decryptedValue = CryptMemoryProtection.DecryptInMemoryData(byteModel.EncryptedValue); // Always check if a directory exists. If not, create it. IOPathHelper.CreateDirectory(currentSaveLocation); // Write the Value of byteModels into a file with the foreignKey as the name. File.WriteAllBytes($"{currentSaveLocation}\\{byteModel.ForeignKey}", decryptedValue); decryptedValue = null; } }
public ChangePasswordView(byte[] encryptedBytes) { InitializeComponent(); Password_Textbox.Text = ByteHelper.ByteArrayToString(CryptMemoryProtection.DecryptInMemoryData(encryptedBytes)); _pwAtStart = Password_Textbox.Text; }
private void Webbrowser_LoadCompleted(object sender, NavigationEventArgs e) { try { if (!_isRun && _isLoginAttempt) { // Get the website document first mshtml.HTMLDocument document = (mshtml.HTMLDocument)Webbrowser.Document; // Set the username var username = document.getElementById("ap_email"); if (username != null) { username.innerText = _username; } // Now for amazon we need to click first var theElementCollection = document.getElementsByTagName("input"); if (theElementCollection != null) { foreach (var el in theElementCollection) { if (((HTMLDTElement)el).id == "continue") { ((HTMLDTElement)el).click(); } } } // Let the page load System.Threading.Thread.Sleep(2000); // Get the newly loaded document document = (mshtml.HTMLDocument)Webbrowser.Document; // Fill in password var pw = document.getElementById("ap_password"); if (pw != null) { pw.innerText = ByteHelper.ByteArrayToString(CryptMemoryProtection.DecryptInMemoryData(_encryptedPassword)); } theElementCollection = document.getElementsByTagName("input"); if (theElementCollection != null) { // Click login button foreach (var el in theElementCollection) { if (((HTMLDTElement)el).id == "signInSubmit") { ((HTMLDTElement)el).click(); } } } Navigation_Textblock.Text = Webbrowser.Source.AbsoluteUri; _isRun = true; } } catch (Exception ex) { Communication.InformUser("Couldn't log into page."); Logger.log.Error($"Couldn't login to page: {ex}"); Close(); } }