sqlcipher / android-database-sqlcipher

Android SQLite API based on SQLCipher
https://www.zetetic.net/sqlcipher/sqlcipher-for-android/
Other
2.73k stars 564 forks source link

Fatal Exception: android.database.sqlite.SQLiteException: file is not a database: , while compiling: select count(*) from sqlite_master; #636

Closed UKMIITB closed 7 months ago

UKMIITB commented 8 months ago
Fatal Exception: android.database.sqlite.SQLiteException: file is not a database: , while compiling: select count(*) from sqlite_master;
       at net.sqlcipher.database.SQLiteCompiledSql.native_compile(SQLiteCompiledSql.java)
       at net.sqlcipher.database.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:89)
       at net.sqlcipher.database.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:62)
       at net.sqlcipher.database.SQLiteProgram.<init>(SQLiteProgram.java:91)
       at net.sqlcipher.database.SQLiteQuery.<init>(SQLiteQuery.java:50)
       at net.sqlcipher.database.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:60)
       at net.sqlcipher.database.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:2019)
       at net.sqlcipher.database.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1905)
       at net.sqlcipher.database.SQLiteDatabase.keyDatabase(SQLiteDatabase.java:2672)
       at net.sqlcipher.database.SQLiteDatabase.openDatabaseInternal(SQLiteDatabase.java:2602)
       at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1250)
       at net.sqlcipher.database.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:1325)
       at net.sqlcipher.database.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:167)
       at net.sqlcipher.database.SupportHelper.getWritableDatabase(SupportHelper.java:83)

In a new update. Added sqlCipher for new database file. implementation "net.zetetic:android-database-sqlcipher:4.5.4"

Implementation wise, I generate one passphrase & save in shared preference permanently. Then using hilt, initialise database as

Room.databaseBuilder(
            context,
            EncryptedDatabase::class.java,
            ENCRYPTED_DATABASE_NAME
        )
            .openHelperFactory(SupportFactory(passphrase))
            .build()

Till now got one crash in Android 5, OPPO device

developernotes commented 8 months ago

Hi @UKMIITB,

It is difficult to say what the root cause of your situation is given the information. This error is common and suggests that SQLCipher for Android was not able to decrypt a file path provided with the supplied password. A few follow-up questions:

dazza5000 commented 7 months ago

This can happen if you are using the wrong/a different passphrase when re-opening the db.

RahulSDeshpande commented 7 months ago

@dazza5000 Your comment is right. I tried to reinstall my Android app with SQLCipher enabled, it worked. 👍🏼

Thanks.

sjlombardo commented 7 months ago

Thanks for confirming that was the problem. Closing this now.