0

Good afternoon.

I am creating an encrypted database file in an Android Application with the following code:

String dbPath = context.getDatabasePath(NAME_OF_MY_FILE).getPath();
SQLiteDatabase sampleDB = SQLiteDatabase.openOrCreateDatabase(dbPath, "password", null);

This works fine and the file is created although when trying to access this encrypted file I get multiple errors such as:

no such table TABLE_NAME and file is encrypted or is not a database

I am simply using the same code to open the file for editing, since the function is called openOrCreateDatabase(). I assume the process to open the file is simply the reverse of creating, and you pass the original password?

Please note I am using the correct import:

import net.sqlcipher.database.SQLiteDatabase; 

and initializing SQLiteDatabase.loadLibs(this); in the onCreate() method.

Can someone please point out where I'm going wrong if they have any idea.

Thank you!

Jens
  • 16,853
  • 4
  • 55
  • 52

2 Answers2

0

After your call to SQLiteDatabase.openOrCreateDatabase, are you creating your database schema there, or are you creating a sublcass of the net.sqlcipher.datdatabase.SQLiteOpenHelper to manage database migrations? Without that your table name would not exist. Maybe you could show more of the code to help diagnose the problem you are seeing.

Nick Parker
  • 1,378
  • 1
  • 7
  • 10
  • Upon creating the file, I immediately create multiple tables using sampleDB.execSQL. As you just said, when I try to open the file in another view I assume all tables are intact (as they are when unencrypted) and attempt to insert. I do not use SQLiteOpenHelper.. do I need to? – user1529205 Jul 16 '12 at 15:42
  • 2
    Depending on your needs, usage of the `net.sqlcipher.database.SQLiteOpenHelper` will be quite beneficial as it will allow you to perform schema migrations as your application changes. It sounds like you are reimplementing this. Possibly check out the [docs](http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html). Also, to rule out your application logic, try throwing in an insert statement following your table creating and see what occurs. – Nick Parker Jul 16 '12 at 18:41
0

You just need to paas "password" in that call.

Chakravyooh
  • 117
  • 7