I need to use SQLCipher for android...i've already made my app using SQLite and want to just convert it to SQLCipher.
The problem is, I know nothing about SQLCipher.
I have read about it in this link: http://sqlcipher.net/sqlcipher-for-android/
But i'm not too clear, still. I was wondering if you could provide some basic sqlcipher for android tutorials, where everything is taught in an easy way from the absolute basics.
Thanks!
To properly use SQL Cipher for Android you must use external libraries and change some of the code which interacts with your DB.
These must first be added to your project (within the libs folder.) Refer here to get these: http://sqlcipher.net/sqlcipher-for-android/
Secondly you need to add the icudt4dl.zip file to your assets folder, this Zip comes with the SQL Cipher libraries.
Right click your project, go to properties then Java build path then include libraries such as commons-codec.jar, guava-r09.jar, sqlcipher.jar. Once this is done, do a build clean.
Then within your App, instead of importing android.database.sqlite, you will import import net.sqlcipher.database
Change any code which interacts with the DB, example:
SQLiteDatabase.loadLibs(context);
String dbPath = this.getDatabasePath("dbname.db").getPath();
SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(dbPath,"dbPassword", null);
Verify that the database is encrypted, go to DDMS perspective in Eclipse, click the file explorer tab, navigate to data/data/, click on the .db file and select get device file, save it to your desktop and open it with a text editor. Look for the plain text values you have been inserting into your database, if you can still read them, something has gone wrong.
It might also be a good idea to check out some SQLite tutorials before implementing SQL Cipher. A good one is mentioned here: Android sqlite database - where do i start as the tutorial has gone for notepad?
Update
This answer is outdated now and Eclipse is practically deprecated for Android Development. I recently had to build an app using SQLCipher on Android Studio for Android 5 + 6 and these are the steps I followed.
In Android Studio, you can include SQLCipher as a dependency in your build file. Update your dependencies in build gradle to include the following line:
dependencies{
compile 'net.zetetic:android-database-sqlcipher:3.5.4@aar'
}
You can keep up to date with versions here: https://mvnrepository.com/artifact/net.zetetic/android-database-sqlcipher
My App wouldn't build unless I removed the SQLCipher files in the lib folder and the asset folder, but after that it worked as expected. Once you made these changes, run a build/clean and check if it works.
The same steps mentioned above with changing your code still stand.
While you can still follow Zetetic's Eclipse tutorial and add .so libraries yourself, you really don't need to do it in Android Studio. Just add a Gradle dependency, like compile net.zetetic:android-database-sqlcipher:3.3.1-2@aar
and you're ready to go!
Here you can always check the latest aar version and here you can read more about integration.
来源:https://stackoverflow.com/questions/17671686/how-to-get-started-with-sqlcipher-for-android