@@ -177,6 +177,7 @@ bool DBBrowserDB::open(const QString& db, bool readOnly)
177177 executeSQL (" PRAGMA kdf_iter = " + std::to_string (cipherSettings->getKdfIterations ()), false , false );
178178 executeSQL (" PRAGMA cipher_hmac_algorithm = " + cipherSettings->getHmacAlgorithm (), false , false );
179179 executeSQL (" PRAGMA cipher_kdf_algorithm = " + cipherSettings->getKdfAlgorithm (), false , false );
180+ executeSQL (" PRAGMA cipher_plaintext_header_size = " + std::to_string (cipherSettings->getPlaintextHeaderSize ()), false , false );
180181 }
181182#endif
182183 delete cipherSettings;
@@ -317,6 +318,11 @@ bool DBBrowserDB::attach(const QString& filePath, QString attach_as)
317318 QMessageBox::warning (nullptr , qApp->applicationName (), lastErrorMessage);
318319 return false ;
319320 }
321+ if (!executeSQL (" PRAGMA cipher_plaintext_header_size = " + std::to_string (cipherSettings->getPlaintextHeaderSize ()), false ))
322+ {
323+ QMessageBox::warning (nullptr , qApp->applicationName (), lastErrorMessage);
324+ return false ;
325+ }
320326 }
321327
322328 if (!executeSQL (" ATTACH " + sqlb::escapeString (filePath.toStdString ()) + " AS " + sqlb::escapeIdentifier (attach_as.toStdString ()) + " " + key, false ))
@@ -360,6 +366,7 @@ bool DBBrowserDB::tryEncryptionSettings(const QString& filePath, bool* encrypted
360366 QString sqlite_version, sqlcipher_version;
361367 getSqliteVersion (sqlite_version, sqlcipher_version);
362368 int enc_default_page_size, enc_default_kdf_iter;
369+ int enc_default_plaintext_header_size = 0 ;
363370 std::string enc_default_hmac_algorithm, enc_default_kdf_algorithm;
364371 if (sqlcipher_version.startsWith (' 4' ))
365372 {
@@ -423,6 +430,7 @@ bool DBBrowserDB::tryEncryptionSettings(const QString& filePath, bool* encrypted
423430
424431 int pageSize = dotenv.value (databaseFileName + " _pageSize" , enc_default_page_size).toInt ();
425432 int kdfIterations = dotenv.value (databaseFileName + " _kdfIter" , enc_default_kdf_iter).toInt ();
433+ int plaintextHeaderSize = dotenv.value (databaseFileName + " _plaintextHeaderSize" , enc_default_kdf_iter).toInt ();
426434 std::string hmacAlgorithm = dotenv.value (databaseFileName + " _hmacAlgorithm" , QString::fromStdString (enc_default_hmac_algorithm)).toString ().toStdString ();
427435 std::string kdfAlgorithm = dotenv.value (databaseFileName + " _kdfAlgorithm" , QString::fromStdString (enc_default_kdf_algorithm)).toString ().toStdString ();
428436
@@ -435,6 +443,7 @@ bool DBBrowserDB::tryEncryptionSettings(const QString& filePath, bool* encrypted
435443 cipherSettings->setKdfIterations (kdfIterations);
436444 cipherSettings->setHmacAlgorithm (hmacAlgorithm);
437445 cipherSettings->setKdfAlgorithm (kdfAlgorithm);
446+ cipherSettings->setPlaintextHeaderSize (plaintextHeaderSize);
438447 }
439448 }
440449
@@ -477,6 +486,8 @@ bool DBBrowserDB::tryEncryptionSettings(const QString& filePath, bool* encrypted
477486 sqlite3_exec (dbHandle, (" PRAGMA cipher_hmac_algorithm = " + cipherSettings->getHmacAlgorithm ()).c_str (), nullptr , nullptr , nullptr );
478487 if (cipherSettings->getKdfAlgorithm () != enc_default_kdf_algorithm)
479488 sqlite3_exec (dbHandle, (" PRAGMA cipher_kdf_algorithm = " + cipherSettings->getKdfAlgorithm ()).c_str (), nullptr , nullptr , nullptr );
489+ if (cipherSettings->getPlaintextHeaderSize () != enc_default_plaintext_header_size)
490+ sqlite3_exec (dbHandle, (" PRAGMA cipher_plaintext_header_size = " + std::to_string (cipherSettings->getPlaintextHeaderSize ())).c_str (), nullptr , nullptr , nullptr );
480491
481492 *encrypted = true ;
482493#else
0 commit comments