public void TestLoad()
        {
            var file    = Data.Json;
            var pfp     = new PfpConvert();
            var entries = pfp.Load(Data.Json, "password");

            Assert.AreEqual("example.com", (entries[0] as SiteEntry).site);
            Assert.AreEqual("user", (entries[1] as GeneratedEntry).name);
            Assert.AreEqual(16, (entries[1] as GeneratedEntry).length);
        }
        public void TestSave()
        {
            var stream = new MemoryStream();
            var pfp    = new PfpConvert();
            var list   = new List <BaseEntry> {
                new StoredEntry {
                    site = "example.com", name = "user", password = "******"
                },
            };

            pfp.Save(stream, "password", list);

            stream.Position = 0;
            var entries = pfp.Load(stream, "password");

            Assert.AreEqual("example.com", (entries[0] as SiteEntry).site);
            Assert.AreEqual("user", (entries[1] as StoredEntry).name);
            Assert.AreEqual("secret", (entries[1] as StoredEntry).password);
        }
Example #3
0
        public override void Import(PwDatabase pwStorage, Stream sInput, IStatusLogger slLogger)
        {
            var form = new OptionForm();

            if (form.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            slLogger.SetText("Decrypting backup...", LogStatusType.Info);

            var pfp     = new PfpConvert();
            var protect = Util.GetMemoryProtection(pwStorage.MemoryProtection);

            protect.Add("PIN");
            protect.Add("PUK");
            protect.Add("CVV");

            var entries = pfp.Load(sInput, form.MasterPassword);
            var pw      = pfp.GetPasswordGetter(form.MasterPassword);

            var i = 0;

            foreach (var baseentry in entries)
            {
                if (!(baseentry is PassEntry entry))
                {
                    continue;
                }

                slLogger.SetText($"Importing {entry.name}@{entry.site}...", LogStatusType.Info);

                var pwEntry = Util.GetKeepassEntry(entry, pw, protect);

                pwStorage.RootGroup.AddEntry(pwEntry, true);
                i++;
            }

            slLogger.SetText($"Imported {i} entries.", LogStatusType.Info);
        }