问题
I compiled the SQLCipher version of the sqlite3 command line shell on Windows and successfully created an encrypted database. I then wanted to see if I could use this premade database in an Android app. I copied the database to an Android app and tried to call SQLiteDatabase.openDatabase and passed in the key I used on Windows, but got the following:
"Caused by: info.guardianproject.database.sqlcipher.SQLiteException: file is encrypted or not a database"
Has anyone tried creating an encrypted database on Windows first and then packaging that database with their application? If so, what's the process for keying and opening the database in the Android app?
I had read the links below, but hadn't found a solution:
https://groups.google.com/group/sqlcipher/browse_thread/thread/d2694975e8f3809f
How to read an encrypted database created previously on pc with sqlcipher on android?
回答1:
If you are using the SQLCipher 2 command line program to create the database you should either:
- Use SQLCipher for Android 2.0.0 (https://github.com/sqlcipher/android-database-sqlcipher/downloads); or
- When creating a database using the command line too, run PRAGMA cipher_use_hmac = OFF immediately after setting the key for the new database to disable HMAC. This will create a 1.1.x compatible database that will work with SQLCipher for Andodi 1.x
来源:https://stackoverflow.com/questions/9742686/sqlcipher-sharing-a-windows-created-database-with-an-android-application