internal static IList <Account> ReadEncryptedAccountXml(string password, string path = "accounts.xml") { if (!string.IsNullOrEmpty(password) && !string.IsNullOrEmpty(path) && File.Exists(path)) { StreamReader reader = new StreamReader(path); string encryptedXml = reader.ReadToEnd(); string decryptedXml = DecryptXml(encryptedXml, password); if (!string.IsNullOrEmpty(decryptedXml)) { StringReader stringReader = new StringReader(decryptedXml); try { XmlSerializer serializer = new XmlSerializer(typeof(XmlAccounts)); XmlAccounts accounts = (XmlAccounts)serializer.Deserialize(stringReader); return(accounts.Account); } catch (Exception ex) { Console.WriteLine(ex.Message); } } } return(null); }
internal static void WriteDecryptedAccountXml(BindingList <Account> accounts, string password, string path = "accounts.xml") { XmlSerializer serializer = new XmlSerializer(typeof(XmlAccounts)); var accountsToSerialize = new XmlAccounts() { Account = accounts }; StringWriter writer = new StringWriter(); serializer.Serialize(writer, accountsToSerialize); var SerializedString = writer.ToString(); if (!string.IsNullOrEmpty(password)) { string encryptedXml = EncryptXml(SerializedString, password); if (!string.IsNullOrEmpty(encryptedXml) && !string.IsNullOrEmpty(path)) { StreamWriter encryptedWriter = new StreamWriter(path); encryptedWriter.Write(encryptedXml); encryptedWriter.Flush(); encryptedWriter.Close(); } } }