Ejemplo n.º 1
0
        public async static Task<PwDatabase> LoadDatabase(IStorageFile database, string password, string keyPath)
        {
            var userKeys = new List<IUserKey>();
            var hasher = new SHA256HasherWP8();
            if (!string.IsNullOrEmpty(password))
            {
                userKeys.Add(await KcpPassword.Create(password, hasher));
            }

            if (!string.IsNullOrEmpty(keyPath))
            {
                var keyfile = await Helpers.Helpers.GetKeyFile(keyPath);
                userKeys.Add(await KcpKeyFile.Create(new WP8File(keyfile), hasher));
            }


            var factory = new KdbReaderFactory(new ManagedCrypto(),
                    new MultiThreadedBouncyCastleCrypto(),
                    new SHA256HasherWP8(),
                    new GZipFactoryWP8());
            var file = await database.AsBuffer();
            var kdbDataReader = new MemoryStream(file.ToArray());

           return await factory.LoadAsync(kdbDataReader, userKeys);
        }