Ejemplo n.º 1
0
        /// <summary>
        /// Gets the saved password.
        /// </summary>
        /// <returns></returns>
        private static DbPersistentData GetSavedPassword(
            IsolatedStorageFile store, string protectPath,
            string parsedXmlPath, string masterPassPath)
        {
            var result = new DbPersistentData();

            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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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());
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Saves user password.
        /// </summary>
        /// <param name="store">The store.</param>
        /// <param name="xml">The XML.</param>
        private 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;
                fs.Write(data, 0, data.Length);
            }
        }