sqlcipher 加密数据库问题3

来源:互联网 发布:建站abc代理商 编辑:程序博客网 时间:2024/06/06 16:33

1、加密数据库sqlcipher 2.1 (大约),运行在android4.4 报错

(1)

09-04 05:15:59.627: E/dalvikvm(1444): dlopen("/data/app-lib/com.glenet.hm-1/libdatabase_sqlcipher.so") failed: dlopen failed: library "/system/lib/libhoudini.so" not found09-04 05:15:59.647: E/AndroidRuntime(1444): FATAL EXCEPTION: main09-04 05:15:59.647: E/AndroidRuntime(1444): Process: com.glenet.hm, PID: 144409-04 05:15:59.647: E/AndroidRuntime(1444): java.lang.UnsatisfiedLinkError: dlopen failed: library "/system/lib/libhoudini.so" not found09-04 05:15:59.647: E/AndroidRuntime(1444): at java.lang.Runtime.loadLibrary(Runtime.java:364)09-04 05:15:59.647: E/AndroidRuntime(1444): at java.lang.System.loadLibrary(System.java:526)09-04 05:15:59.647: E/AndroidRuntime(1444): at net.sqlcipher.database.SQLiteDatabase.loadLibs(SQLiteDatabase.java:143)09-04 05:15:59.647: E/AndroidRuntime(1444): at net.sqlcipher.database.SQLiteDatabase.loadLibs(SQLiteDatabase.java:136)09-04 05:15:59.647: E/AndroidRuntime(1444): at com.glenet.hm.sys.HmApplication.onCreate(HmApplication.java:80)09-04 05:15:59.647: E/AndroidRuntime(1444): at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)09-04 05:15:59.647: E/AndroidRuntime(1444): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4344)09-04 05:15:59.647: E/AndroidRuntime(1444): at android.app.ActivityThread.access$1500(ActivityThread.java:135)09-04 05:15:59.647: E/AndroidRuntime(1444): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)09-04 05:15:59.647: E/AndroidRuntime(1444): at android.os.Handler.dispatchMessage(Handler.java:102)09-04 05:15:59.647: E/AndroidRuntime(1444): at android.os.Looper.loop(Looper.java:136)09-04 05:15:59.647: E/AndroidRuntime(1444): at android.app.ActivityThread.main(ActivityThread.java:5017)09-04 05:15:59.647: E/AndroidRuntime(1444): at java.lang.reflect.Method.invokeNative(Native Method)09-04 05:15:59.647: E/AndroidRuntime(1444): at java.lang.reflect.Method.invoke(Method.java:515)09-04 05:15:59.647: E/AndroidRuntime(1444): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)09-04 05:15:59.647: E/AndroidRuntime(1444): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)09-04 05:15:59.647: E/AndroidRuntime(1444): at dalvik.system.NativeStart.main(Native Method)

(2)红米1s 等


09-09 13:34:02.665: E/dalvikvm(7536): dlopen("/data/app-lib/com.glenet.hm-1/libdatabase_sqlcipher.so") failed: dlopen failed: cannot locate symbol "_ZN7android10MemoryBaseC1ERKNS_2spINS_11IMemoryHeapEEElj" referenced by "libdatabase_sqlcipher.so"...09-09 13:34:02.668: E/AndroidRuntime(7536): FATAL EXCEPTION: main09-09 13:34:02.668: E/AndroidRuntime(7536): Process: com.glenet.hm, PID: 753609-09 13:34:02.668: E/AndroidRuntime(7536): java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "_ZN7android10MemoryBaseC1ERKNS_2spINS_11IMemoryHeapEEElj" referenced by "libdatabase_sqlcipher.so"...09-09 13:34:02.668: E/AndroidRuntime(7536): at java.lang.Runtime.loadLibrary(Runtime.java:371)09-09 13:34:02.668: E/AndroidRuntime(7536): at java.lang.System.loadLibrary(System.java:531)09-09 13:34:02.668: E/AndroidRuntime(7536): at net.sqlcipher.database.SQLiteDatabase.loadLibs(SQLiteDatabase.java:143)09-09 13:34:02.668: E/AndroidRuntime(7536): at net.sqlcipher.database.SQLiteDatabase.loadLibs(SQLiteDatabase.java:136)09-09 13:34:02.668: E/AndroidRuntime(7536): at com.glenet.hm.sys.HmApplication.onCreate(HmApplication.java)09-09 13:34:02.668: E/AndroidRuntime(7536): at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)09-09 13:34:02.668: E/AndroidRuntime(7536): at com.lbe.security.service.core.client.b.x.callApplicationOnCreate(Unknown Source)09-09 13:34:02.668: E/AndroidRuntime(7536): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4564)09-09 13:34:02.668: E/AndroidRuntime(7536): at android.app.ActivityThread.access$1500(ActivityThread.java:151)09-09 13:34:02.668: E/AndroidRuntime(7536): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1402)09-09 13:34:02.668: E/AndroidRuntime(7536): at android.os.Handler.dispatchMessage(Handler.java:110)09-09 13:34:02.668: E/AndroidRuntime(7536): at android.os.Looper.loop(Looper.java:193)09-09 13:34:02.668: E/AndroidRuntime(7536): at android.app.ActivityThread.main(ActivityThread.java:5315)09-09 13:34:02.668: E/AndroidRuntime(7536): at java.lang.reflect.Method.invokeNative(Native Method)09-09 13:34:02.668: E/AndroidRuntime(7536): at java.lang.reflect.Method.invoke(Method.java:515)09-09 13:34:02.668: E/AndroidRuntime(7536): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)09-09 13:34:02.668: E/AndroidRuntime(7536): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:660)09-09 13:34:02.668: E/AndroidRuntime(7536): at dalvik.system.NativeStart.main(Native Method)



解决:

升级数据库, 2.2.2及以上版本

建议升级到2.2.2 ,因为3.1 与2.x 不是完美兼容,

若从2.x升级到到3.x 读取数据库会报错哦,见下方


2、程序使用sqlcipher2.2 升级到 3.1 ,程序安装后 打开会报错

同样,从3.1降级到2.2 也会报错


09-04 12:24:25.010: E/lights(2773): write_int: path /sys/devices/virtual/misc/melfas_touchkey/brightness, value 109-04 12:24:26.020: E/Database(3612): CREATE TABLE android_metadata failed09-04 12:24:26.020: E/Database(3612): Failed to setLocale() when constructing, closing the database09-04 12:24:26.020: E/Database(3612): net.sqlcipher.database.SQLiteException: file is encrypted or is not a database09-04 12:24:26.020: E/Database(3612): at net.sqlcipher.database.SQLiteDatabase.native_setLocale(Native Method)09-04 12:24:26.020: E/Database(3612): at net.sqlcipher.database.SQLiteDatabase.setLocale(SQLiteDatabase.java:2092)09-04 12:24:26.020: E/Database(3612): at net.sqlcipher.database.SQLiteDatabase.<init>(SQLiteDatabase.java:1958)09-04 12:24:26.020: E/Database(3612): at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:875)09-04 12:24:26.020: E/Database(3612): at net.sqlcipher.database.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:907)09-04 12:24:26.020: E/Database(3612): at net.sqlcipher.database.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:132)09-04 12:24:26.020: E/Database(3612): at net.sqlcipher.database.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:197)09-04 12:24:26.020: E/Database(3612): at net.sqlcipher.database.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:184)09-04 12:24:26.020: E/Database(3612): at com.glenet.hm.sqlite.HmAppDbHelper.getReadableDatabase(HmAppDbHelper.java:77)09-04 12:24:26.020: E/Database(3612): at com.glenet.hm.sqlite.DbTableIsExist.tabbleIsExist(DbTableIsExist.java:22)09-04 12:24:26.020: E/Database(3612): at com.glenet.hm.sys.HmApplication.initTable(HmApplication.java:144)09-04 12:24:26.020: E/Database(3612): at com.glenet.hm.sys.HmApplication.onCreate(HmApplication.java:83)09-04 12:24:26.020: E/Database(3612): at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:972)09-04 12:24:26.020: E/Database(3612): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3280)09-04 12:24:26.020: E/Database(3612): at android.app.ActivityThread.access$2200(ActivityThread.java:117)09-04 12:24:26.020: E/Database(3612): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:973)09-04 12:24:26.020: E/Database(3612): at android.os.Handler.dispatchMessage(Handler.java:99)09-04 12:24:26.020: E/Database(3612): at android.os.Looper.loop(Looper.java:130)09-04 12:24:26.020: E/Database(3612): at android.app.ActivityThread.main(ActivityThread.java:3691)09-04 12:24:26.020: E/Database(3612): at java.lang.reflect.Method.invokeNative(Native Method)09-04 12:24:26.020: E/Database(3612): at java.lang.reflect.Method.invoke(Method.java:507)09-04 12:24:26.020: E/Database(3612): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)09-04 12:24:26.020: E/Database(3612): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670)09-04 12:24:26.020: E/Database(3612): at dalvik.system.NativeStart.main(Native Method)09-04 12:24:26.025: E/SQLiteOpenHelper(3612): Couldn't open hm.db for writing (will try read-only):09-04 12:24:26.025: E/SQLiteOpenHelper(3612): net.sqlcipher.database.SQLiteException: file is encrypted or is not a database09-04 12:24:26.025: E/SQLiteOpenHelper(3612): at net.sqlcipher.database.SQLiteDatabase.native_setLocale(Native Method)09-04 12:24:26.025: E/SQLiteOpenHelper(3612): at net.sqlcipher.database.SQLiteDatabase.setLocale(SQLiteDatabase.java:2092)09-04 12:24:26.025: E/SQLiteOpenHelper(3612): at net.sqlcipher.database.SQLiteDatabase.<init>(SQLiteDatabase.java:1958)09-04 12:24:26.025: E/SQLiteOpenHelper(3612): at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:875)09-04 12:24:26.025: E/SQLiteOpenHelper(3612): at net.sqlcipher.database.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:907)09-04 12:24:26.025: E/SQLiteOpenHelper(3612): at net.sqlcipher.database.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:132)09-04 12:24:26.025: E/SQLiteOpenHelper(3612): at net.sqlcipher.database.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:197)09-04 12:24:26.025: E/SQLiteOpenHelper(3612): at net.sqlcipher.database.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:184)09-04 12:24:26.025: E/SQLiteOpenHelper(3612): at com.glenet.hm.sqlite.HmAppDbHelper.getReadableDatabase(HmAppDbHelper.java:77)09-04 12:24:26.025: E/SQLiteOpenHelper(3612): at com.glenet.hm.sqlite.DbTableIsExist.tabbleIsExist(DbTableIsExist.java:22)09-04 12:24:26.025: E/SQLiteOpenHelper(3612): at com.glenet.hm.sys.HmApplication.initTable(HmApplication.java:144)09-04 12:24:26.025: E/SQLiteOpenHelper(3612): at com.glenet.hm.sys.HmApplication.onCreate(HmApplication.java:83)09-04 12:24:26.025: E/SQLiteOpenHelper(3612): at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:972)09-04 12:24:26.025: E/SQLiteOpenHelper(3612): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3280)09-04 12:24:26.025: E/SQLiteOpenHelper(3612): at android.app.ActivityThread.access$2200(ActivityThread.java:117)09-04 12:24:26.025: E/SQLiteOpenHelper(3612): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:973)09-04 12:24:26.025: E/SQLiteOpenHelper(3612): at android.os.Handler.dispatchMessage(Handler.java:99)09-04 12:24:26.025: E/SQLiteOpenHelper(3612): at android.os.Looper.loop(Looper.java:130)09-04 12:24:26.025: E/SQLiteOpenHelper(3612): at android.app.ActivityThread.main(ActivityThread.java:3691)09-04 12:24:26.025: E/SQLiteOpenHelper(3612): at java.lang.reflect.Method.invokeNative(Native Method)09-04 12:24:26.025: E/SQLiteOpenHelper(3612): at java.lang.reflect.Method.invoke(Method.java:507)09-04 12:24:26.025: E/SQLiteOpenHelper(3612): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)09-04 12:24:26.025: E/SQLiteOpenHelper(3612): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670)09-04 12:24:26.025: E/SQLiteOpenHelper(3612): at dalvik.system.NativeStart.main(Native Method)09-04 12:24:26.550: E/lights(2773): write_int: path /sys/devices/virtual/misc/melfas_touchkey/brightness, value 209-04 12:24:26.600: E/Database(3612): CREATE TABLE android_metadata failed09-04 12:24:26.610: E/Database(3612): Failed to setLocale() when constructing, closing the database09-04 12:24:26.610: E/Database(3612): net.sqlcipher.database.SQLiteException: file is encrypted or is not a database09-04 12:24:26.610: E/Database(3612): at net.sqlcipher.database.SQLiteDatabase.native_setLocale(Native Method)09-04 12:24:26.610: E/Database(3612): at net.sqlcipher.database.SQLiteDatabase.setLocale(SQLiteDatabase.java:2092)09-04 12:24:26.610: E/Database(3612): at net.sqlcipher.database.SQLiteDatabase.<init>(SQLiteDatabase.java:1958)09-04 12:24:26.610: E/Database(3612): at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:875)09-04 12:24:26.610: E/Database(3612): at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:934)09-04 12:24:26.610: E/Database(3612): at net.sqlcipher.database.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:219)09-04 12:24:26.610: E/Database(3612): at net.sqlcipher.database.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:184)09-04 12:24:26.610: E/Database(3612): at com.glenet.hm.sqlite.HmAppDbHelper.getReadableDatabase(HmAppDbHelper.java:77)09-04 12:24:26.610: E/Database(3612): at com.glenet.hm.sqlite.DbTableIsExist.tabbleIsExist(DbTableIsExist.java:22)09-04 12:24:26.610: E/Database(3612): at com.glenet.hm.sys.HmApplication.initTable(HmApplication.java:144)09-04 12:24:26.610: E/Database(3612): at com.glenet.hm.sys.HmApplication.onCreate(HmApplication.java:83)09-04 12:24:26.610: E/Database(3612): at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:972)09-04 12:24:26.610: E/Database(3612): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3280)09-04 12:24:26.610: E/Database(3612): at android.app.ActivityThread.access$2200(ActivityThread.java:117)09-04 12:24:26.610: E/Database(3612): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:973)09-04 12:24:26.610: E/Database(3612): at android.os.Handler.dispatchMessage(Handler.java:99)09-04 12:24:26.610: E/Database(3612): at android.os.Looper.loop(Looper.java:130)09-04 12:24:26.610: E/Database(3612): at android.app.ActivityThread.main(ActivityThread.java:3691)09-04 12:24:26.610: E/Database(3612): at java.lang.reflect.Method.invokeNative(Native Method)09-04 12:24:26.610: E/Database(3612): at java.lang.reflect.Method.invoke(Method.java:507)09-04 12:24:26.610: E/Database(3612): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)09-04 12:24:26.610: E/Database(3612): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670)09-04 12:24:26.610: E/Database(3612): at dalvik.system.NativeStart.main(Native Method)09-04 12:24:27.190: E/Database(3612): CREATE TABLE android_metadata failed09-04 12:24:27.190: E/Database(3612): Failed to setLocale() when constructing, closing the database09-04 12:24:27.190: E/Database(3612): net.sqlcipher.database.SQLiteException: file is encrypted or is not a database09-04 12:24:27.190: E/Database(3612): at net.sqlcipher.database.SQLiteDatabase.native_setLocale(Native Method)09-04 12:24:27.190: E/Database(3612): at net.sqlcipher.database.SQLiteDatabase.setLocale(SQLiteDatabase.java:2092)09-04 12:24:27.190: E/Database(3612): at net.sqlcipher.database.SQLiteDatabase.<init>(SQLiteDatabase.java:1958)09-04 12:24:27.190: E/Database(3612): at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:875)09-04 12:24:27.190: E/Database(3612): at net.sqlcipher.database.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:907)09-04 12:24:27.190: E/Database(3612): at net.sqlcipher.database.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:132)09-04 12:24:27.190: E/Database(3612): at net.sqlcipher.database.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:197)09-04 12:24:27.190: E/Database(3612): at net.sqlcipher.database.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:184)09-04 12:24:27.190: E/Database(3612): at com.glenet.hm.sqlite.HmAppDbHelper.getReadableDatabase(HmAppDbHelper.java:77)09-04 12:24:27.190: E/Database(3612): at com.glenet.hm.sqlite.DbTableIsExist.tabbleIsExist(DbTableIsExist.java:22)09-04 12:24:27.190: E/Database(3612): at com.glenet.hm.sys.HmApplication.initTable(HmApplication.java:146)09-04 12:24:27.190: E/Database(3612): at com.glenet.hm.sys.HmApplication.onCreate(HmApplication.java:83)09-04 12:24:27.190: E/Database(3612): at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:972)09-04 12:24:27.190: E/Database(3612): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3280)09-04 12:24:27.190: E/Database(3612): at android.app.ActivityThread.access$2200(ActivityThread.java:117)09-04 12:24:27.190: E/Database(3612): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:973)09-04 12:24:27.190: E/Database(3612): at android.os.Handler.dispatchMessage(Handler.java:99)09-04 12:24:27.190: E/Database(3612): at android.os.Looper.loop(Looper.java:130)09-04 12:24:27.190: E/Database(3612): at android.app.ActivityThread.main(ActivityThread.java:3691)09-04 12:24:27.190: E/Database(3612): at java.lang.reflect.Method.invokeNative(Native Method)09-04 12:24:27.190: E/Database(3612): at java.lang.reflect.Method.invoke(Method.java:507)09-04 12:24:27.190: E/Database(3612): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)09-04 12:24:27.190: E/Database(3612): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670)09-04 12:24:27.190: E/Database(3612): at dalvik.system.NativeStart.main(Native Method)09-04 12:24:27.195: E/SQLiteOpenHelper(3612): Couldn't open hm.db for writing (will try read-only):09-04 12:24:27.195: E/SQLiteOpenHelper(3612): net.sqlcipher.database.SQLiteException: file is encrypted or is not a database09-04 12:24:27.195: E/SQLiteOpenHelper(3612): at net.sqlcipher.database.SQLiteDatabase.native_setLocale(Native Method)09-04 12:24:27.195: E/SQLiteOpenHelper(3612): at net.sqlcipher.database.SQLiteDatabase.setLocale(SQLiteDatabase.java:2092)09-04 12:24:27.195: E/SQLiteOpenHelper(3612): at net.sqlcipher.database.SQLiteDatabase.<init>(SQLiteDatabase.java:1958)09-04 12:24:27.195: E/SQLiteOpenHelper(3612): at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:875)09-04 12:24:27.195: E/SQLiteOpenHelper(3612): at net.sqlcipher.database.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:907)09-04 12:24:27.195: E/SQLiteOpenHelper(3612): at net.sqlcipher.database.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:132)09-04 12:24:27.195: E/SQLiteOpenHelper(3612): at net.sqlcipher.database.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:197)09-04 12:24:27.195: E/SQLiteOpenHelper(3612): at net.sqlcipher.database.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:184)09-04 12:24:27.195: E/SQLiteOpenHelper(3612): at com.glenet.hm.sqlite.HmAppDbHelper.getReadableDatabase(HmAppDbHelper.java:77)09-04 12:24:27.195: E/SQLiteOpenHelper(3612): at com.glenet.hm.sqlite.DbTableIsExist.tabbleIsExist(DbTableIsExist.java:22)09-04 12:24:27.195: E/SQLiteOpenHelper(3612): at com.glenet.hm.sys.HmApplication.initTable(HmApplication.java:146)09-04 12:24:27.195: E/SQLiteOpenHelper(3612): at com.glenet.hm.sys.HmApplication.onCreate(HmApplication.java:83)09-04 12:24:27.195: E/SQLiteOpenHelper(3612): at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:972)09-04 12:24:27.195: E/SQLiteOpenHelper(3612): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3280)09-04 12:24:27.195: E/SQLiteOpenHelper(3612): at android.app.ActivityThread.access$2200(ActivityThread.java:117)09-04 12:24:27.195: E/SQLiteOpenHelper(3612): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:973)09-04 12:24:27.195: E/SQLiteOpenHelper(3612): at android.os.Handler.dispatchMessage(Handler.java:99)09-04 12:24:27.195: E/SQLiteOpenHelper(3612): at android.os.Looper.loop(Looper.java:130)09-04 12:24:27.195: E/SQLiteOpenHelper(3612): at android.app.ActivityThread.main(ActivityThread.java:3691)09-04 12:24:27.195: E/SQLiteOpenHelper(3612): at java.lang.reflect.Method.invokeNative(Native Method)09-04 12:24:27.195: E/SQLiteOpenHelper(3612): at java.lang.reflect.Method.invoke(Method.java:507)09-04 12:24:27.195: E/SQLiteOpenHelper(3612): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)09-04 12:24:27.195: E/SQLiteOpenHelper(3612): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670)09-04 12:24:27.195: E/SQLiteOpenHelper(3612): at dalvik.system.NativeStart.main(Native Method)09-04 12:24:27.740: E/Database(3612): CREATE TABLE android_metadata failed09-04 12:24:27.740: E/Database(3612): Failed to setLocale() when constructing, closing the database09-04 12:24:27.740: E/Database(3612): net.sqlcipher.database.SQLiteException: file is encrypted or is not a database09-04 12:24:27.740: E/Database(3612): at net.sqlcipher.database.SQLiteDatabase.native_setLocale(Native Method)09-04 12:24:27.740: E/Database(3612): at net.sqlcipher.database.SQLiteDatabase.setLocale(SQLiteDatabase.java:2092)09-04 12:24:27.740: E/Database(3612): at net.sqlcipher.database.SQLiteDatabase.<init>(SQLiteDatabase.java:1958)09-04 12:24:27.740: E/Database(3612): at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:875)09-04 12:24:27.740: E/Database(3612): at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:934)09-04 12:24:27.740: E/Database(3612): at net.sqlcipher.database.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:219)09-04 12:24:27.740: E/Database(3612): at net.sqlcipher.database.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:184)09-04 12:24:27.740: E/Database(3612): at com.glenet.hm.sqlite.HmAppDbHelper.getReadableDatabase(HmAppDbHelper.java:77)09-04 12:24:27.740: E/Database(3612): at com.glenet.hm.sqlite.DbTableIsExist.tabbleIsExist(DbTableIsExist.java:22)09-04 12:24:27.740: E/Database(3612): at com.glenet.hm.sys.HmApplication.initTable(HmApplication.java:146)09-04 12:24:27.740: E/Database(3612): at com.glenet.hm.sys.HmApplication.onCreate(HmApplication.java:83)09-04 12:24:27.740: E/Database(3612): at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:972)09-04 12:24:27.740: E/Database(3612): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3280)09-04 12:24:27.740: E/Database(3612): at android.app.ActivityThread.access$2200(ActivityThread.java:117)09-04 12:24:27.740: E/Database(3612): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:973)09-04 12:24:27.740: E/Database(3612): at android.os.Handler.dispatchMessage(Handler.java:99)09-04 12:24:27.740: E/Database(3612): at android.os.Looper.loop(Looper.java:130)09-04 12:24:27.740: E/Database(3612): at android.app.ActivityThread.main(ActivityThread.java:3691)09-04 12:24:27.740: E/Database(3612): at java.lang.reflect.Method.invokeNative(Native Method)09-04 12:24:27.740: E/Database(3612): at java.lang.reflect.Method.invoke(Method.java:507)09-04 12:24:27.740: E/Database(3612): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)09-04 12:24:27.740: E/Database(3612): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670)09-04 12:24:27.740: E/Database(3612): at dalvik.system.NativeStart.main(Native Method)


解决(未完善):


http://stackoverflow.com/questions/20614096/android-sqlchipher-net-sqlcipher-database-sqliteexception-file-is-encrypted-or


https://www.zetetic.net/blog/2013/11/11/sqlcipher-300-release.html


https://www.zetetic.net/sqlcipher/sqlcipher-api/


The same thing has happened to me and it is because after the update of the SQLCipher library i also needed to upgrade the database from the version 1.1.x i was using to 2.2.2. See here why. To do that you need to use the SQLiteDatabase.upgradeDatabaseFormatFromVersion1To2(File dbPath, String key). The problem is that this method does not preserve the db version so we need to do that manually. So the code will be like this:

 //Open the old formatted db with cipher_use_hmac = OFF; SQLiteDatabaseHook hook = new SQLiteDatabaseHook() {     public void preKey(SQLiteDatabase database) {}     public void postKey(SQLiteDatabase database) {         database.rawExecSQL("PRAGMA cipher_use_hmac = OFF;");     } }; //Read the db version SQLiteDatabase old_db = SQLiteDatabase.openOrCreateDatabase(path, mPassword, mFactory, hook); int version = old_db.getVersion(); old_db.close(); //Do the upgrade to 2.x format try {     SQLiteDatabase.upgradeDatabaseFormatFromVersion1To2(new File(path), mPassword); } catch (Exception e) {     e.printStackTrace(); }//Manually set the db version to the updated db.SQLiteDatabase updated_db = SQLiteDatabase.openOrCreateDatabase(path, mPassword, mFactory);updated_db.setVersion(version);

The above code will permanently update the SQLCipher database format to 2.2.2 version. If you want to update to the new 3.x format, the process is different and you need to use the PRAGMA cipher_migrate method (See here). I avoided the 3.x format because the default KDF iteration count is 64000 (up from 4000) which was making the readings/writings to the database quite slow. The 2.2.2 version is compatible with KitKat.


3、附下载地址


2.2.2 包含so库

https://s3.amazonaws.com/sqlcipher/SQLCipher+for+Android+v2.2.2.zip 

2.2.2 源码,不含二进制文件

https://github.com/sqlcipher/android-database-sqlcipher/archive/v2.2.2.zip

3.1包含so库

https://s3.amazonaws.com/sqlcipher/SQLCipher+for+Android+v3.1.0.zip

3.1 源码,不含二进制文件

https://github.com/sqlcipher/android-database-sqlcipher/archive/v3.1.0.zip


所有版本-源码,不含二进制文件

https://github.com/sqlcipher/android-database-sqlcipher/releases



0 0
原创粉丝点击