1

Is there any way to verify that a file is a valid SQLite database with SQLCipher, without knowing the encryption key? In other words, are there any checksums or magic words that do not get encrypted?

From this post I understand normal SQLite 3 databases just start with the string "sqlite 3", and if I know the password I could check validity of the actual high-level database structure using this.

The error message “file is encrypted or is not a database” found here suggests that the answer is no - but can anybody confirm?

2 Answers 2

4

No. An encrypted database file is indistinguishable from a file containing random data.

Sign up to request clarification or add additional context in comments.

Comments

1

I solve by this code in constructor of DBHelper (it is not pure clean, but it works...)

private DBHelper() {
    SQLiteDatabase.loadLibs(context);

    File dbFile = context.getDatabasePath(DB_NAME);

    try {
        if (dbFile.exists()) { // is db file exists?
            // check if db file can be opened
            SQLiteDatabase.openDatabase(dbFile.getAbsolutePath(), DB_PASSWORD, null, SQLiteDatabase.OPEN_READWRITE).close();
        }
    } catch (SQLiteException ex) { // it's impossible open db file - we must encrypt it
        encryptDatabase(context, dbFile);
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.