【发布时间】:2014-06-24 11:56:43
【问题描述】:
从最近 3 天开始,我正在尝试将我的数据库升级到更高版本的 SQLCipher 库 (v3.1.0)。我做了每一步,也遵循了一些教程。但继续收到错误“文件已加密或不是数据库”。现在我试图转移到未加密的数据库,即。简单的 sqlite 数据库。 我们有办法将加密数据库转移到未加密数据库吗?提前致谢。
这是我正在处理的代码:
public MyDBAdapter(Context context) {
this.context = context;
File dbFile = context.getDatabasePath(DATABASE_NAME);
String dbPath = context.getDatabasePath(DATABASE_NAME).toString();
if (dbFile.exists()) {
try {
SQLiteDatabase.loadLibs(context.getApplicationContext());//load SqlCipher libraries
SQLiteDatabase db = getExistDataBaseFile(dbPath, KEY_PASSPHRASE_ENCRYPTION, dbFile);
if (version == 1) {
MigrateDatabaseFrom1xFormatToCurrentFormat(
dbFile, KEY_PASSPHRASE_ENCRYPTION);
}
System.out.println("Old Database found and updated.");
} catch (Exception e) {
System.out.println("No Old Database found");
}
}
this.dbhelper = new MyDBHelper(this.context, DATABASE_NAME, null,
DATABASE_Version);
db = dbhelper.getWritableDatabase(KEY_PASSPHRASE_ENCRYPTION);
}
private SQLiteDatabase getExistDataBaseFile(String FULL_DB_Path, String password, File dbFile) {// this function to open an Exist database
SQLiteDatabase.loadLibs(context.getApplicationContext());
SQLiteDatabaseHook hook = new SQLiteDatabaseHook() {
public void preKey(SQLiteDatabase database) {
System.out.println("-----Inside preKey");
}
public void postKey(SQLiteDatabase database) {
System.out.println("-----Inside postKey");
database.rawExecSQL("PRAGMA cipher_migrate;");
}
};
SQLiteDatabase database = SQLiteDatabase.openOrCreateDatabase(
dbFile, "Test123", null, hook); // Exception
return database;
}
【问题讨论】:
-
您不能再使用您的 SQLCipher 版本?
-
感谢您的回复。早些时候,当我创建我的应用程序时,我使用了 sqlcipher v2.x.x 现在我想迁移到 3.1.0 但不能这样做。所以现在我想解密我的数据库,让它变成一个普通的数据库。
-
感谢您的帮助。我会检查链接是否有效。我还是想知道为什么 SQLiteDatabase.openOrCreateDatabase(FULL_DB_Path, password, null, hook);无法打开加密文件并显示错误“文件已加密或 id 不是数据库”
-
请编辑您的答案。在更新和回答之前发布您使用的代码。可能是它帮助stackoverflow用户帮助你。
标签: android sqlite encryption migration sqlcipher