如何使用GreenDAO库加密Android中的现有数据库



我正在使用GreenDAO库从旧版本升级到新版本后,我遇到SQL异常例:Version 1.0:数据库未加密版本2.0:数据库已加密使用 1.0 的现有用户升级到 2.0调用此函数后我收到异常,在此之前,我必须在升级时加密较旧的数据库。怎么做?

helper.getEncryptedWritableDb(password);

net.sqlcipher.database.SQLiteException: file is encrypted or is not a database: , while compiling: select count(*) from sqlite_master;
at net.sqlcipher.database.SQLiteCompiledSql.native_compile(Native Method)
at net.sqlcipher.database.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:91)
at net.sqlcipher.database.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:64)
at net.sqlcipher.database.SQLiteProgram.<init>(SQLiteProgram.java:84)
at net.sqlcipher.database.SQLiteQuery.<init>(SQLiteQuery.java:49)
at net.sqlcipher.database.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42)
at net.sqlcipher.database.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1820)
at net.sqlcipher.database.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1785)
at net.sqlcipher.database.SQLiteDatabase.keyDatabase(SQLiteDatabase.java:2439)
at net.sqlcipher.database.SQLiteDatabase.openDatabaseInternal(SQLiteDatabase.java:2368)
at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1149)
at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1041)
at net.sqlcipher.database.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:249)
at net.sqlcipher.database.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:214)
at org.greenrobot.greendao.database.DatabaseOpenHelper.getEncryptedWritableDb(DatabaseOpenHelper.java:134)
at org.broadsoft.iris.datamodel.db.DatabaseManager.openWritableDb(DatabaseManager.java:149)
at org.broadsoft.iris.datamodel.db.DatabaseManager.openReadableDb(DatabaseManager.java:129)
at org.broadsoft.iris.datamodel.db.DatabaseManager.getContactIdsInMessageHistory(DatabaseManager.java:461)
at org.broadsoft.iris.http.HttpManagerV2.lambda$fetchVCards$2(HttpManagerV2.java:573)
at org.broadsoft.iris.http.HttpManagerV2.access$lambda$2(HttpManagerV2.java)
at org.broadsoft.iris.http.HttpManagerV2$$Lambda$3.run(Unknown Source)
at java.lang.Thread.run(Thread.java:761)

没有从SQLite(未加密(到SQLCipher(加密(的"升级"。这是如何做到这一点的大纲:

  1. 打开SQLite数据库
  2. 使用不同的名称打开 SQLCipher 数据库以确保使用不同的数据库文件
  3. 从 SQLite 读取数据
  4. 将数据写入 SQLCipher

相关内容

  • 没有找到相关文章

最新更新