private static IEnumerable <Credentials> getCredentialList() { try { // Get syncInfo from file, written by GroupSync WebAPI using (var tr = new StreamReader(Path.Combine(Main.GetFolderPath(), "Credentials.txt"))) { return(JsonConvert.DeserializeObject <List <Credentials> >(StringCipher.decrypt(tr.ReadToEnd(), StringCipher.getKey()))); } } catch (Exception) { return(new List <Credentials>()); } }
private void saveCredentials() { var credList = (from DataGridViewRow row in credDataView.Rows select new Credentials { alias = row.Cells[0].Value?.ToString(), key = row.Cells[1].Value?.ToString(), secret = row.Cells[2].Value?.ToString() }).ToList(); var savePath = Path.Combine(Main.GetFolderPath(), "Credentials.txt"); try { using (TextWriter tw = new StreamWriter(savePath)) { tw.Write(StringCipher.encrypt(JsonConvert.SerializeObject(credList), StringCipher.getKey())); MessageBox.Show(@"Credentials Saved"); _promptSave = false; } } catch (IOException e) { // something happened? MessageBox.Show(e.Message); } }