/// <summary> /// Initialize LiteEngine using custom disk service implementation and full engine options /// </summary> public LiteEngine(IDiskService disk, string password = null, TimeSpan?timeout = null, bool autocommit = true, int cacheSize = 5000, Logger log = null) { _timeout = timeout ?? TimeSpan.FromMinutes(1); _cacheSize = cacheSize; _autocommit = autocommit; _disk = disk; _log = log ?? new Logger(); _locker = new Locker(_timeout); // initialize datafile (create) and set log instance _disk.Initialize(_log, password); // read header page var header = BasePage.ReadPage(_disk.ReadPage(0)) as HeaderPage; // hash password with sha1 or keep as empty byte[20] var sha1 = password == null ? new byte[20] : AesEncryption.HashSHA1(password); // compare header password with user password even if not passed password (datafile can have password) if (sha1.BinaryCompareTo(header.Password) != 0) { // explicit dispose _disk.Dispose(); throw LiteException.DatabaseWrongPassword(); } // initialize AES encryptor if (password != null) { _crypto = new AesEncryption(password, header.Salt); } // initialize all services this.InitializeServices(); if (_disk.IsJournalEnabled) { // try recovery if has journal file _trans.Recovery(); } }
/// <summary> /// Initialize LiteEngine using custom disk service implementation and full engine options /// </summary> public LiteEngine(IDiskService disk, string password = null, TimeSpan? timeout = null, bool autocommit = true, int cacheSize = 5000, Logger log = null) { _timeout = timeout ?? TimeSpan.FromMinutes(1); _cacheSize = cacheSize; _autocommit = autocommit; _disk = disk; _log = log ?? new Logger(); _locker = new Locker(_timeout); // initialize datafile (create) and set log instance _disk.Initialize(_log, password); // read header page var header = BasePage.ReadPage(_disk.ReadPage(0)) as HeaderPage; // hash password with sha1 or keep as empty byte[20] var sha1 = password == null ? new byte[20] : AesEncryption.HashSHA1(password); // compare header password with user password even if not passed password (datafile can have password) if (sha1.BinaryCompareTo(header.Password) != 0) { // explicit dispose _disk.Dispose(); throw LiteException.DatabaseWrongPassword(); } // initialize AES encryptor if (password != null) { _crypto = new AesEncryption(password, header.Salt); } // initialize all services this.InitializeServices(); if (_disk.IsJournalEnabled) { // try recovery if has journal file _trans.Recovery(); } }