public static Database Load(DbPersistentData data, Dispatcher dispatcher) { if (data == null) throw new ArgumentNullException("data"); using (var buffer = new MemoryStream(data.Xml)) { var crypto = CryptoSerializer .Deserialize(data.Protection); return new XmlParser(crypto, buffer, dispatcher) .Parse(); } }
/// <summary> /// Saves user password. /// </summary> /// <param name="store">The store.</param> /// <param name="xml">The XML.</param> private async void Save(IsolatedStorageFile store, DbPersistentData xml) { if (!store.DirectoryExists(Folder)) store.CreateDirectory(Folder); using (var fs = store.CreateFile(ProtectionPath)) { var protect = xml.Protection; fs.Write(protect, 0, protect.Length); } using (var fs = store.CreateFile(ParsedXmlPath)) using (var buffer = new MemoryStream(xml.Xml)) BufferEx.CopyStream(buffer, fs); using (var fs = store.CreateFile(MasterPasswordPath)) { var data = xml.MasterKey; await fs.WriteAsync(data, 0, data.Length); } }
private void Open(IsolatedStorageFile store, DbPersistentData xml, Dispatcher dispatcher) { var database = DatabaseReader .Load(xml, dispatcher); var name = HasPassword ? Folder : string.Empty; if (Details == null) LoadDetails(store); Data = xml; Cache.CacheDb(this, name, database); }
/// <summary> /// Gets the saved password. /// </summary> /// <returns></returns> private static DbPersistentData GetSavedPassword( IsolatedStorageFile store, string protectPath, string parsedXmlPath, string masterPassPath) { var result = new DbPersistentData(); if (!store.FileExists(protectPath)) { throw new FileNotFoundException(protectPath); } if (!store.FileExists(parsedXmlPath)) { throw new FileNotFoundException(parsedXmlPath); } if (!store.FileExists(masterPassPath)) { throw new FileNotFoundException(masterPassPath); } using (var fs = store.OpenFile(protectPath, FileMode.Open)) using (var buffer = new MemoryStream((int)fs.Length)) { BufferEx.CopyStream(fs, buffer); result.Protection = buffer.ToArray(); } using (var fs = store.OpenFile(parsedXmlPath, FileMode.Open)) using (var buffer = new MemoryStream((int)fs.Length)) { BufferEx.CopyStream(fs, buffer); result.Xml = buffer.ToArray(); } using (var fs = store.OpenFile(masterPassPath, FileMode.Open)) using (var buffer = new MemoryStream((int)fs.Length)) { BufferEx.CopyStream(fs, buffer); result.MasterKey = buffer.ToArray(); } return result; }