/// <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(); }
/// <summary> /// Save the contents of the current <c>PwDatabase</c> to a KDB file. /// </summary> /// <param name="strSaveToFile">Location to save the KDB file to.</param> public void Save(string strSaveToFile, PwGroup pgDataSource) { Debug.Assert(strSaveToFile != null); if (strSaveToFile == null) { throw new ArgumentNullException("strSaveToFile"); } KdbManager mgr = new KdbManager(); KdbErrorCode e = KdbFile.SetDatabaseKey(mgr, m_pwDatabase.MasterKey); if (e != KdbErrorCode.Success) { Debug.Assert(false); throw new Exception(KLRes.InvalidCompositeKey); } if (m_slLogger != null) { if (m_pwDatabase.Name.Length != 0) { m_slLogger.SetText(KdbPrefix + KPRes.FormatNoDatabaseName, LogStatusType.Warning); } if (m_pwDatabase.Description.Length != 0) { m_slLogger.SetText(KdbPrefix + KPRes.FormatNoDatabaseDesc, LogStatusType.Warning); } } // Set properties if (m_pwDatabase.KeyEncryptionRounds >= (ulong)UInt32.MaxValue) { mgr.KeyTransformationRounds = unchecked (uint.MaxValue - 1); } else { mgr.KeyTransformationRounds = (uint)m_pwDatabase.KeyEncryptionRounds; } PwGroup pgRoot = (pgDataSource ?? m_pwDatabase.RootGroup); // Write groups and entries Dictionary <PwGroup, UInt32> dictGroups = WriteGroups(mgr, pgRoot); WriteEntries(mgr, dictGroups, pgRoot); e = mgr.SaveDatabase(strSaveToFile); if (e != KdbErrorCode.Success) { throw new Exception(KLRes.FileSaveFailed); } mgr.Unload(); }
public static bool IsLibraryInstalled(out Exception ex) { try { KdbManager mgr = new KdbManager(); mgr.Unload(); } catch (Exception exMgr) { ex = exMgr; return(false); } ex = null; return(true); }