GreenDAO cannot access existed database after upgrading sqlcipher from 3.5.2 to 4.0.1

浪子不回头ぞ 提交于 2019-12-11 10:48:46

问题


I'm using GreenDAO with SQLCipher. After I upgrade SQLCipher from 3.5.2 to 4.0.1, my app cannot access the old encrypted database. I have already searched for a solution and found out that I need to run PRAGMA cipher_migrate in postKey of the SQLiteDatabaseHook to migrate my database. I tried like this, but nothing changes.:

    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();

来源:https://stackoverflow.com/questions/54785383/greendao-cannot-access-existed-database-after-upgrading-sqlcipher-from-3-5-2-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!