很久以前,我已经将sqlcipher集成到我们的项目中。由于某些安全问题,我们必须升级sqlcipher的版本。我已经浏览了以下链接
但是我不知道在哪里添加该代码。如何将他们的代码与我的代码集成。
这是我的Logcat
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.axis.leadsloans, PID: 8798
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.axis.leadsloans/com.axis.leadsloans.nnmnu}: net.sqlcipher.database.SQLiteException: file is not a database: , while compiling: select count(*) from sqlite_master;
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2928)
Caused by: net.sqlcipher.database.SQLiteException: file is not a database: , while compiling: select count(*) from sqlite_master;
这是我的数据库相关代码。
public class CRMDB {
private SQLiteHelper sqLiteHelper;
public SQLiteDatabase sqLiteDatabase;
private Context context;
.
.
.
public CRMDB(Context c) {
context = c;
String s = "";
SQLiteDatabase.loadLibs(c);
SharedPreferences prefs = c.getSharedPreferences(Constants.PREFERENCE_NAME, Activity.MODE_PRIVATE);
empid = prefs.getString("empid", "");
}
public CRMDB openToWrite() throws SQLiteFullException {
sqLiteHelper = new SQLiteHelper(context, MYDATABASE_NAME + "_" + empid + ".db", null, MYDATABASE_VERSION);
//App get crash on this line
sqLiteDatabase = sqLiteHelper.getWritableDatabase("password");
return this;
}
public CRMDB openToRead() throws SQLiteFullException {
sqLiteHelper = new SQLiteHelper(context, MYDATABASE_NAME + "_" + empid + ".db", null, MYDATABASE_VERSION);
sqLiteDatabase = sqLiteHelper.getReadableDatabase("password");
return this;
}
public long insertData(String tablename, ContentValues contentvalue) {
return sqLiteDatabase.insert(tablename, null, contentvalue);
}
public Cursor getData(String query) {
Cursor c = sqLiteDatabase.rawQuery(query, null);
return c;
}
public long updateData(String tablename, ContentValues contentvalue, String where, String whereArgs[]) {
return sqLiteDatabase.update(tablename, contentvalue, where, whereArgs);
}
public class SQLiteHelper extends SQLiteOpenHelper {
public SQLiteHelper(Context context, String name, CursorFactory factory, int version) {
super(context, name, factory, version);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(tb_task_createtable);
db.execSQL(tb_calls_createtable);
db.execSQL(tb_messages_table);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
}
请帮助我理解这一点。
答案 0 :(得分:2)
your second link中的讨论显示了如何为此设置SQLiteDatabaseHook
:
SQLiteDatabaseHook mHook = new SQLiteDatabaseHook() {
public void preKey(SQLiteDatabase database) {
}
public void postKey(SQLiteDatabase database) {
database.rawExecSQL("PRAGMA cipher_compatibility=3;");
database.rawExecSQL("PRAGMA kdf_iter=1000;");
database.rawExecSQL("PRAGMA cipher_default_kdf_iter=1000;");
database.rawExecSQL("PRAGMA cipher_page_size = 4096;");
}
};
然后更改:
public SQLiteHelper(Context context, String name, CursorFactory factory, int version) {
super(context, name, factory, version);
}
收件人:
public SQLiteHelper(Context context, String name, CursorFactory factory, int version) {
super(context, name, factory, version, mHook);
}
将钩子提供给SQLiteOpenHelper
构造函数。