Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
258 views
in Technique[技术] by (71.8m points)

android - file is encrypted or is not a database (Exception net.sqlcipher.database.SQLiteException)

I'm trying to use sqlcipher lib to encrypt my database from already existing database but while accessing the old database(i.e opening the db) gives this exception:

 02-27 13:12:21.231: E/AndroidRuntime(14687): FATAL EXCEPTION: main
 02-27 13:12:21.231: E/AndroidRuntime(14687): java.lang.RuntimeException: Unable to start activity ComponentInfo{net.sqlcipher/example.SQLDemoActivity}: net.sqlcipher.database.SQLiteException: file is encrypted or is not a database
 02-27 13:12:21.231: E/AndroidRuntime(14687):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
 02-27 13:12:21.231: E/AndroidRuntime(14687):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2211)
 02-27 13:12:21.231: E/AndroidRuntime(14687):   at android.app.ActivityThread.access$600(ActivityThread.java:149)
 02-27 13:12:21.231: E/AndroidRuntime(14687):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1300)
 02-27 13:12:21.231: E/AndroidRuntime(14687):   at android.os.Handler.dispatchMessage(Handler.java:99)
 02-27 13:12:21.231: E/AndroidRuntime(14687):   at android.os.Looper.loop(Looper.java:153)
 02-27 13:12:21.231: E/AndroidRuntime(14687):   at android.app.ActivityThread.main(ActivityThread.java:4987)
 02-27 13:12:21.231: E/AndroidRuntime(14687):   at java.lang.reflect.Method.invokeNative(Native Method)
 02-27 13:12:21.231: E/AndroidRuntime(14687):   at java.lang.reflect.Method.invoke(Method.java:511)
 02-27 13:12:21.231: E/AndroidRuntime(14687):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
 02-27 13:12:21.231: E/AndroidRuntime(14687):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
 02-27 13:12:21.231: E/AndroidRuntime(14687):   at dalvik.system.NativeStart.main(Native Method)
 02-27 13:12:21.231: E/AndroidRuntime(14687): Caused by: net.sqlcipher.database.SQLiteException: file is encrypted or is not a database
 02-27 13:12:21.231: E/AndroidRuntime(14687):   at net.sqlcipher.database.SQLiteDatabase.native_setLocale(Native Method)
 02-27 13:12:21.231: E/AndroidRuntime(14687):   at net.sqlcipher.database.SQLiteDatabase.setLocale(SQLiteDatabase.java:2102)
 02-27 13:12:21.231: E/AndroidRuntime(14687):   at net.sqlcipher.database.SQLiteDatabase.<init>(SQLiteDatabase.java:1968)
 02-27 13:12:21.231: E/AndroidRuntime(14687):   at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:901)
 02-27 13:12:21.231: E/AndroidRuntime(14687):   at net.sqlcipher.database.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:944)
 02-27 13:12:21.231: E/AndroidRuntime(14687):   at net.sqlcipher.database.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:107)
 02-27 13:12:21.231: E/AndroidRuntime(14687):   at example.SQLDemoActivity.onCreate(SQLDemoActivity.java:42)
 02-27 13:12:21.231: E/AndroidRuntime(14687):   at android.app.Activity.performCreate(Activity.java:5020)
 02-27 13:12:21.231: E/AndroidRuntime(14687):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
 02-27 13:12:21.231: E/AndroidRuntime(14687):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
 02-27 13:12:21.231: E/AndroidRuntime(14687):   ... 11 more

since my old db is not encrypted so what should I set password in that case

I have tried with passing null in password string and also with "" but with no luck

reported issue to https://github.com/sqlcipher/android-database-sqlcipher/issues/124

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

since my old db is not encrypted so what should i set password in that case

SQLCipher for Android can open an unencrypted database using "" as the password.

i have tried with passing null in password string and also with "" but no luck

Then either:

  • You have a bug in your code, or
  • The database is already encrypted with another password, or
  • The database is corrupted.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...