【发布时间】:2016-01-12 04:07:45
【问题描述】:
我的 android 应用程序使用提供的数据库填充并位于 asset 文件夹中。我最近不得不开始在其中添加私人数据,所以我使用sqlcipher 对其进行加密。所以在开始之前:
加密进行得很顺利,因为我可以轻松解密并读回它。这是通过
sqlcipher shell完成的。数据库没有加密,一切都像魅力一样工作
我所做的是,在我的应用程序第一次启动时,在我的手机上创建一个空白数据库,复制并粘贴其中提供的数据库的内容,然后,用户可以在他的电话,而不必每次都重新创建它(数据库很大)。事实上,如果用户已经在他的手机上拥有数据库以供进一步启动,他就不必以这种方式重新创建它。
但是对于sqlcipher,它不再起作用了。
重要提示:当使用带有非加密数据库的 sqlcipher 时(使用“”作为相关方法的参数,如 openDatabase),它也可以正常工作。
但是当我尝试使用加密数据库和密码时,我得到的是错误
file is encrypted or is not a database: create locale table failed
这发生在我使用这个创建一个空白数据库之后:
//By calling this method and empty database will be created into the default system path
//of your application so we are gonna be able to overwrite that database with our database.
this.getReadableDatabase("password").close();
然后我尝试按照以下说明打开它:
//Open the database
String myPath = DB_PATH + DATABASE_NAME;
myDataBase = SQLiteDatabase.openDatabase(myPath, "password", null, SQLiteDatabase.OPEN_READWRITE);
然后发生错误。有人有想法吗?遗憾的是,我不是 android 专家,使用 db 已经很困难,但你可以猜到它现在正在进入另一个层次。欢迎任何帮助。提前致谢!
【问题讨论】:
标签: android encryption android-sqlite sqlcipher