PRAGMA cipher_migrate fails for Android Pie only. I see that the return value is 1 (inspected via cursor.getSTring(0), but I don’t know how to get additional information as to why the error is occurring.
How can I do that? Is the only way to run the pragma from the CLI using the community command line shell?
Hello @Matt_Dupree
I’m sorry to hear you are experiencing an issue with migration. A couple of follow-up questions:
- What version of SQLCipher was used to create the database you are attempting to migrate?
- Did you use any non-default runtime settings when creating the database you are attempting to migrate?
You can also run the same pragma cipher_migrate
using the command line shell.
Appreciate the response. Turns out the migration was failing because we had updated our target Android SDK version. We figured out why and have implemented a work around.
Hi @Matt_Dupree - thanks for getting back to us to let us know this is resolved. Could you explain a bit more how the target SDK change impacted the migration? It would be good to know the details in case anyone runs into this in the future. Thanks!
Our situation was pretty unique. We were using Build.SERIAL as a part of the key to access the database and the behavior of Build.SERIAL changed when we updated the target SDK version
Hi everyone!
I’ve studied couple of threads related to migration issues on Android similar to this one Upgrading to SQLCipher 4 but still facing some problems.
The app is using SqlCipher for Android v3.5.7 together with OrmLite. I need to switch to Room Persistence Library but to do that I need to update version of SqlCipher to latest one since it’s compatible with Room.
So, current implementation (with v3.5.7) has custom settings described in the hook’s postkey
database.rawExecSQL("PRAGMA cipher_page_size = 2048;");
database.rawExecSQL("PRAGMA cipher = 'aes-128-cfb';");
database.rawExecSQL("PRAGMA kdf_iter = 20000;");
As was suggested the proper way to do it is custom export migration. So, after those three line from the hook I’m calling this function to migrate my db.
fun migrateToCipher4(context: Context, database: SQLiteDatabase) {
val newDbName = "<my-new-db-name>"
val newDbFile = context.getDatabasePath("$newDbName.db")
val newDbPath = newDbFile.absolutePath
val newDbKey = "<my-new-db-password>"
val newDbVersion = 1
val dbHelper = DatabaseHelper4(context, "$newDbName.db", null, newDbVersion, newDbKey)
val db = dbHelper.getWritableDatabase(newDbKey)
db.close()
dbHelper.close()
database.rawExecSQL("ATTACH DATABASE '$newDbPath' AS $newDbName KEY '$newDbKey';")
database.rawExecSQL("SELECT sqlcipher_export('$newDbName');")
database.rawExecSQL("DETACH DATABASE $newDbName;")
}
But it fails during execution of ATTACH query with ‘file is not a database’ error.
net.sqlcipher.database.SQLiteException: file is not a database
at net.sqlcipher.database.SQLiteDatabase.native_rawExecSQL(Native Method)
Besides, new db file is created and I can open it with DB browser for SQLite with default SqlCipher4 settings. But it’s empty since error happens before export query runs.
Any ideas what could’ve been missing? Thanks in advance.
Hi @kemeyo4490
As part of the SQLCipher 4.0.0 release, the PRAGMA cipher
command is now disabled and no longer supported (after multi-year deprecation). So you will likely need to convert your databases using 3.5.7 to use the standard cipher (AES 256 in CBC mode) before you are able to upgrade, or create a custom build of SQLCipher for Android to support your needs.
4 posts were merged into an existing topic: SQLCipher(v) compatibility with openssl(v)