public static void Main(string[] args) { CompositeKey key = new CompositeKey(); KcpPassword pw = new KcpPassword("12345"); key.AddUserKey(pw); byte[] pwdata = pw.KeyData.ReadData(); Console.WriteLine("PW data:"); Console.WriteLine(string.Join(",", pwdata.Select(x => "0x" + x.ToString("x")))); byte[] keydata = key.GenerateKey32(pwdata, 6000).ReadData(); Console.WriteLine("Key data:"); Console.WriteLine(string.Join(",", keydata.Select(x => "0x" + x.ToString("x")))); PwDatabase db = new PwDatabase(); db.MasterKey = key; KdbxFile kdbx = new KdbxFile(db); kdbx.Load(@"..\resources\test.kdbx", KdbxFormat.Default, null); var groups = db.RootGroup.GetGroups(true); Console.WriteLine("Group count: " + groups.UCount); var entries = db.RootGroup.GetEntries(true); Console.WriteLine("Entry count: " + entries.UCount); CompositeKey key2 = new CompositeKey(); key2.AddUserKey(pw); KcpKeyFile keyfile = new KcpKeyFile(@"..\resources\keyfile.key"); key2.AddUserKey(keyfile); byte[] keyfiledata = keyfile.KeyData.ReadData(); Console.WriteLine("Key file data:"); Console.WriteLine(string.Join(",", keyfiledata.Select(x => "0x" + x.ToString("x")))); Console.WriteLine("Composite Key data:"); byte[] key2data = key2.GenerateKey32(keyfiledata, 6000).ReadData(); Console.WriteLine(string.Join(",", key2data.Select(x => "0x" + x.ToString("x")))); }
/// <summary> /// This function checks if the actual SyncSource (this) represents exactly the same /// SyncSource that would occur if we will use the given entry and db to create a new one. /// </summary> /// <param name="entry">The PwEntry from our db that should represent a SyncSource.</param> /// <param name="db">The db which contains the given entry.</param> /// <returns>True if (entry + db) will create the same SyncSource object like "this".</returns> public bool IsEqual(PwEntry entry, PwDatabase db) { if (!IsSimilar(entry, db)) { return false; } IUserKey key1 = new KcpPassword( entry.Strings.ReadSafe( KeeShare.PasswordField ) ); IUserKey key2 = m_key.GetUserKey( typeof( KcpPassword ) ); // null is interpreted as equal return (key1 == key2 || key1.KeyData.Equals(key2.KeyData)); }