public async static Task<PwDatabase> LoadDatabase(IStorageFile database, string password, string keyPath) { var userKeys = new List<IUserKey>(); var hasher = new SHA256HasherRT(); 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 WinRTFile(keyfile), hasher)); } var readerFactory = new KdbReaderFactory( new WinRTCrypto(), new MultiThreadedBouncyCastleCrypto(), new SHA256HasherRT(), new GZipFactoryRT()); var file = await FileIO.ReadBufferAsync(database); MemoryStream kdbDataReader = new MemoryStream(file.AsBytes()); return await readerFactory.LoadAsync(kdbDataReader, userKeys); }
public async void OpenDatabase() { OpeningDatabase = true; var userKeys = new List<IUserKey>(); var sHA256HasherRT = new SHA256HasherRT(); if (!string.IsNullOrEmpty(Password)) { userKeys.Add(await KcpPassword.Create(Password, sHA256HasherRT)); } if (KeyFile != null) { userKeys.Add(await KcpKeyFile.Create(new WinRTFile(KeyFile), sHA256HasherRT)); } var progress = new Progress<double>(percent => { percent = Math.Round(percent, 2); Progress = percent; }); try { await _dataSource.LoadPwDatabase(Database, userKeys, progress); OpeningDatabase = false; var encodedUUID = _dataSource.PwDatabase.Tree.Group.UUID; if (ShouldRedirectToSearch) { _navigationService.UriFor<EntryGroupListViewModel>().WithParam(vm => vm.GroupId, encodedUUID).Navigate(); _navigationService.UriFor<SearchResultsViewModel>().WithParam(vm => vm.QueryText, SearchText).Navigate(); } else { _navigationService.UriFor<EntryGroupListViewModel>().WithParam(vm => vm.GroupId, encodedUUID).Navigate(); } } catch (Exception se) { OpeningDatabase = false; Progress = 0; _pageServices.Toast(se.Message); } }