WeChat for Android uses SQLCipher to encrypt its data, however the file format is incompatible with SQLCipher 3.x. When i tried to migrate the database file format in my Android app using SQLCipher for Android 3.3.1, things do not work out for me.
Here is my code:
SQLiteDatabase.loadLibs(context);
SQLiteDatabaseHook hook = new SQLiteDatabaseHook() {
public void preKey(SQLiteDatabase database) {
}
public void postKey(SQLiteDatabase database) {
database.rawExecSQL("PRAGMA cipher_use_hmac = off;");
database.rawExecSQL("PRAGMA cipher_page_size = 1024;");
database.rawExecSQL("PRAGMA kdf_iter = 4000;");
Cursor cursor = database.rawQuery("PRAGMA cipher_migrate", new String[]{});
if (cursor != null) {
cursor.moveToFirst();
Log.d(TAG, "cipher_migrate return code: " + cursor.getString(0));
cursor.close();
} else {
Log.d(TAG, "cipher_migrate return cursor is null");
}
}
};
SQLiteDatabase database = SQLiteDatabase.openOrCreateDatabase(dbFile, "password", null, hook);
database.close();
When i executed PRAGMA cipher_migrate
in the postKey
method of SQLiteDatabaseHook
, i got a return code of 1.
The full logcat messages can be found here http://pastebin.com/sbszqP63
Thanks,
Clyde