我有一个使用System.Data.SQLite从现有应用程序中导出的加密SQLite数据库文件。基于我所能找到的,System.Data.SQLite使用128位RC4加密。Android SQLCipher RC4加密数据库文件“文件已加密或不是数据库”
当我尝试使用SQLCipher在我的Android应用程序中加载此数据库时,出现以下错误“文件已加密或不是数据库”。我试过使用数据库钩子来设置杂注键= rc4,但这似乎没有帮助。我能找到的唯一一个可以打开这个数据库文件的程序是SQLite2009 Pro Enterprise Manager。它不会打开它,允许我浏览并运行查询。
这里是代码我目前正在使用:
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());
}
什么我做错了任何想法?