我正在使用 GreenDAO
和 SQLCipher
。
将 SQLCipher
从 3.5.2 升级到 4.0.1 后,我的应用无法访问旧的加密数据库。
我已经搜索了一个解决方案,发现我需要在 SQLiteDatabaseHook
的 postKey
中运行 PRAGMA cipher_migrate 来迁移我的数据库。我这样试过,但没有任何改变。:
SQLiteDatabaseHook hook = new SQLiteDatabaseHook() {
@Override
public void preKey(SQLiteDatabase database) {
}
@Override
public void postKey(SQLiteDatabase database) {
database.execSQL("PRAGMA key = '" + key + "';");
database.execSQL("PRAGMA cipher_migrate;");
}
};
Database db = new EncryptedDatabase(SQLiteDatabase.openOrCreateDatabase("DB.db", key, null, hook));
return new DaoMaster(db).newSession();
最佳答案
当 "DB.db"
需要路径时,您将其传递给 openOrCreateDatabase
。你想做这样的事情:
File dbPathFile = new File(path);
if (!dbPathFile.exists()) {
dbPathFile.getParentFile().mkdirs();
}
然后在 openOrCreateDatabase
"DB.db"
的地方传递 path
关于android - 将 sqlcipher 从 3.5.2 升级到 4.0.1 后,GreenDAO 无法访问现有数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54785383/