diff --git a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp --- a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp +++ b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp @@ -1851,11 +1851,8 @@ throw std::runtime_error("invalid backupLogDataKey size"); } - std::string rekey_encryption_key_query = - "PRAGMA rekey = \"x'" + backupDataKey + "'\";"; - - executeQuery( - SQLiteQueryExecutor::getConnection(), rekey_encryption_key_query); + SQLiteUtils::rekeyDatabase( + SQLiteQueryExecutor::getConnection(), backupDataKey); CommSecureStore::set(CommSecureStore::backupDataKey, backupDataKey); SQLiteQueryExecutor::backupDataKey = backupDataKey; diff --git a/native/cpp/CommonCpp/DatabaseManagers/SQLiteUtils.h b/native/cpp/CommonCpp/DatabaseManagers/SQLiteUtils.h --- a/native/cpp/CommonCpp/DatabaseManagers/SQLiteUtils.h +++ b/native/cpp/CommonCpp/DatabaseManagers/SQLiteUtils.h @@ -27,6 +27,7 @@ static void validateEncryption( const std::string &sqliteFilePath, const std::string &encryptionKey); + static void rekeyDatabase(sqlite3 *db, const std::string &encryptionKey); }; } // namespace comm diff --git a/native/cpp/CommonCpp/DatabaseManagers/SQLiteUtils.cpp b/native/cpp/CommonCpp/DatabaseManagers/SQLiteUtils.cpp --- a/native/cpp/CommonCpp/DatabaseManagers/SQLiteUtils.cpp +++ b/native/cpp/CommonCpp/DatabaseManagers/SQLiteUtils.cpp @@ -1,6 +1,7 @@ #include "SQLiteUtils.h" #include "Logger.h" +#include "entities/EntityQueryHelpers.h" #include #include @@ -200,4 +201,10 @@ Logger::log("Encryption completed successfully."); } +void SQLiteUtils::rekeyDatabase(sqlite3 *db, const std::string &encryptionKey) { + std::string rekey_encryption_key_query = + "PRAGMA rekey = \"x'" + encryptionKey + "'\";"; + executeQuery(db, rekey_encryption_key_query); +} + } // namespace comm