@@ -4,9 +4,8 @@ import android.content.Context
44import android.database.Cursor
55import io.kommunicate.devkit.api.MobiComKitClientService
66import io.kommunicate.commons.AppContextService
7- import net.sqlcipher.database.SQLiteDatabase
8- import net.sqlcipher.database.SQLiteException
9- import kotlin.Throws
7+ import net.zetetic.database.sqlcipher.SQLiteDatabase
8+ import android.database.sqlite.SQLiteException
109
1110object DatabaseMigrationHelper {
1211 private const val TEMP_ENCRYPTED_DB_NAME = " temp_encrypted.db"
@@ -34,7 +33,7 @@ object DatabaseMigrationHelper {
3433 MobiComKitClientService .getApplicationKey(AppContextService .getContext(context))
3534
3635 // Load SQLCipher libraries
37- SQLiteDatabase .loadLibs(context )
36+ System .loadLibrary( " sqlcipher " )
3837
3938 // File paths for unencrypted and temporary encrypted databases
4039 val unencryptedDbFile = context.getDatabasePath(databaseName)
@@ -45,18 +44,19 @@ object DatabaseMigrationHelper {
4544 }
4645
4746 // Open the unencrypted database
48- val unencryptedDb = SQLiteDatabase .openDatabase(
47+ val unencryptedDb = android.database.sqlite. SQLiteDatabase .openDatabase(
4948 unencryptedDbFile.path,
50- " " , // Empty string since it's not encrypted
5149 null ,
52- SQLiteDatabase .OPEN_READWRITE
50+ android.database.sqlite. SQLiteDatabase .OPEN_READWRITE
5351 )
5452
53+
5554 // Create the temporary encrypted database
5655 val encryptedDb = SQLiteDatabase .openOrCreateDatabase(
5756 encryptedTempDbFile.path,
58- password, // Password for encryption
59- null
57+ password.toByteArray(Charsets .UTF_8 ), // Convert the password String to a byte array
58+ null , // CursorFactory
59+ null // SQLiteDatabaseHook
6060 )
6161
6262 // Copy data from unencrypted to encrypted database
@@ -81,7 +81,7 @@ object DatabaseMigrationHelper {
8181
8282 // Copy tables and data from one database to another
8383 @Throws(Exception ::class )
84- private fun copyDataBetweenDatabases (sourceDb : SQLiteDatabase , destinationDb : SQLiteDatabase ) {
84+ private fun copyDataBetweenDatabases (sourceDb : android.database.sqlite. SQLiteDatabase , destinationDb : SQLiteDatabase ) {
8585 val cursor: Cursor =
8686 sourceDb.rawQuery(" SELECT name FROM sqlite_master WHERE type='table'" , null )
8787 if (cursor.moveToFirst()) {
@@ -126,7 +126,7 @@ object DatabaseMigrationHelper {
126126 }
127127
128128 // Get the CREATE TABLE SQL statement for a specific table
129- private fun getTableCreateSql (db : SQLiteDatabase , tableName : String ): String? {
129+ private fun getTableCreateSql (db : android.database.sqlite. SQLiteDatabase , tableName : String ): String? {
130130 val cursor: Cursor = db.rawQuery(
131131 " SELECT sql FROM sqlite_master WHERE type='table' AND name=?" ,
132132 arrayOf(tableName)
0 commit comments