aanm
aanm

Reputation: 41

How to read an encrypted database created previously on pc with sqlcipher on android?

I'm trying to read an encrypted database created with sqlcipher on my PC but I can't read it on my app. For example:

Cursor c = database.rawQuery("SELECT name FROM sqlite_master WHERE type='table'", null);
    c.moveToFirst();
    do {
        String s = c.getString(0);
        if (s.equals("android_metadata")) {
            // System.out.println("Get Metadata");
            continue;
        } else {
            dirArray.add(s);
        }
    } while (c.moveToNext());
    Log.i("getS", "DATABASE = " + dirArray.toString());
    Log.i("getS", "length = " + dirArray.size());

result on the following

03-12 03:28:12.691: I/getS(9895): DATABASE = []
03-12 03:28:12.691: I/getS(9895): length = 0

also this:

Cursor c2 = database.query("my_table", new String[] { "name" }, null, null, null, null, "name");

return in to this:

03-12 03:28:12.701: I/Database(9895): sqlite returned: error code = 1, msg = no such table: my_table

I'm compiling with sdk-7, if I try the same database unencrypted and without the sqlcipher, I don't have any problems. Could anyone teach me how do I read on android a database encrypted on my computer? Appreciate ;)

Upvotes: 3

Views: 1626

Answers (1)

Nick Parker
Nick Parker

Reputation: 1388

You will want to use the SQLCipher for Android library which will allow you to access and modify a sqlcipher database on an Android device. We currently support Android 2.1 - 4.0.3. Binary downloads can be found here:

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

A tutorial on itegrating SQLCipher for Android can be found here:

http://sqlcipher.net/sqlcipher-for-android/

Upvotes: 1

Related Questions