I have an encyprted SQLite database file that is being exported from an existing application using System.Data.SQLite. Based on what I can find, System.Data.SQLite uses 128-bit RC4 encryption.
When I try to load this database in my Android application with SQLCipher, I get the following error "file is encrypted or is not a database". I have tried using a database hook which sets the pragma key = rc4, but this does not seem to help. The only program I have been able to find that can open this database file is SQLite2009 Pro Enterprise Manager. It opens it with no issue, allows me to browse, and run queries.
Here is the code I am currently using:
try
{
SQLiteDatabase.loadLibs(activity);
//this function copies the db file from the project assets to the data/databases folder
copydatabase();
File databaseFile = activity.getApplicationContext().getDatabasePath("someDB.db3");
SQLiteDatabaseHook hook = new SQLiteDatabaseHook(){
public void preKey(SQLiteDatabase database){
database.execSQL("pragma cipher = rc4");
}
public void postKey(SQLiteDatabase database){
database.execSQL("pragma cipher = rc4");
}
};
SQLiteDatabase database = SQLiteDatabase.openDatabase(databaseFile.getAbsolutePath(), "mypassword", null, SQLiteDatabase.NO_LOCALIZED_COLLATORS|SQLiteDatabase.OPEN_READWRITE, hook);
Cursor cursor = database.rawQuery("SELECT * FROM SOMETABLE;", null);
if (cursor.moveToFirst()){
do{
String data = cursor.getString(cursor.getColumnIndex("SOME_COLUMN"));
}while(cursor.moveToNext());
}
cursor.close();
}
catch(Exception ex)
{
Log.e(ex.getMessage().toString(), ex.getStackTrace().toString());
}
Any ideas on what I am doing wrong?