/// <summary> /// Loads a KDB file and stores all loaded entries in the current /// PwDatabase instance. /// </summary> /// <param name="strFilePath">Relative or absolute path to the file to open.</param> public void Load(string strFilePath) { Debug.Assert(strFilePath != null); if (strFilePath == null) { throw new ArgumentNullException("strFilePath"); } using (KdbManager mgr = new KdbManager()) { KdbErrorCode e; e = KdbFile.SetDatabaseKey(mgr, m_pwDatabase.MasterKey); if (e != KdbErrorCode.Success) { throw new Exception(KLRes.InvalidCompositeKey); } e = mgr.OpenDatabase(strFilePath, IntPtr.Zero); if (e != KdbErrorCode.Success) { throw new Exception(KLRes.FileLoadFailed); } // Copy properties m_pwDatabase.KdfParameters = (new AesKdf()).GetDefaultParameters(); m_pwDatabase.KdfParameters.SetUInt64(AesKdf.ParamRounds, mgr.KeyTransformationRounds); // Read groups and entries Dictionary <UInt32, PwGroup> dictGroups = ReadGroups(mgr); ReadEntries(mgr, dictGroups); } }
/// <summary> /// Loads a KDB file and stores all loaded entries in the current /// PwDatabase instance. /// </summary> /// <param name="strFilePath">Relative or absolute path to the file to open.</param> public void Load(string strFilePath) { Debug.Assert(strFilePath != null); if (strFilePath == null) { throw new ArgumentNullException("strFilePath"); } KdbManager mgr = new KdbManager(); KdbErrorCode e; e = KdbFile.SetDatabaseKey(mgr, m_pwDatabase.MasterKey); if (e != KdbErrorCode.Success) { throw new Exception(KLRes.InvalidCompositeKey); } e = mgr.OpenDatabase(strFilePath, IntPtr.Zero); if (e != KdbErrorCode.Success) { mgr.Unload(); throw new Exception(KLRes.FileLoadFailed); } // Copy properties m_pwDatabase.KeyEncryptionRounds = mgr.KeyTransformationRounds; // Read groups and entries Dictionary <UInt32, PwGroup> dictGroups = ReadGroups(mgr); ReadEntries(mgr, dictGroups); mgr.Unload(); }