Using PRAGMA key in SQLCipher command line client not working with Android DB

1,390 views
Skip to first unread message

Nick Danukarjanto

unread,
Dec 16, 2013, 1:13:00 PM12/16/13
to sqlc...@googlegroups.com
Hi Guys,

I have an Android app using SQLCipher and I know the encryption is working since I have pulled the sqlite DB file off of a device and checked. However, I am not able to query the DB that was pulled off of the device using the command line tool even after setting the key. The DB works completely fine on the android device by the app, but I can't get to the data directly.

I get the DB in the app using:  SQLiteDatabase db = helper.getWritableDatabase("test");

On the command line tool I always get "Error: file is encrypted or is not a database" when using the following: 
PRAGMA key='test';
select * from sqlite_master;

I can create an encrypted DB locally using the command line tool and can key it to run queries, but I've never been able to get the data from the Android app DB.

Am I missing something?

Thanks for any help,
Nick

Nick Parker

unread,
Dec 16, 2013, 1:17:15 PM12/16/13
to sqlc...@googlegroups.com
Hello Nick,

Can you verify what versions of SQLCipher you are using on both
SQLCipher for Android and the SQLCipher command line shell? You can
find these by executing the following:

PRAGMA cipher_version;
> --
>
> ---
> You received this message because you are subscribed to the Google
> Groups "SQLCipher Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to sqlcipher+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

--
Nick Parker

signature.asc

Nick Danukarjanto

unread,
Dec 16, 2013, 1:39:27 PM12/16/13
to sqlc...@googlegroups.com
Hi Nick,

Thanks for the quick response.

SQLCipher for Android is 2.2.2 and the command line shell is 3.0.0. After updating SQLCipher for Android to 3.0.0, I am able to run queries on the command line client after keying, but I have another issue.

If I attempt to upgrade my app with v3.0.0 on top of an installation that was using v2.2.2, I get the error "net.sqlcipher.database.SQLiteException: file is encrypted or is not a database". It works fine for a fresh install, but upgrades fail. Am I missing a step when upgrading the DB?

Nick Parker

unread,
Dec 16, 2013, 2:37:01 PM12/16/13
to sqlc...@googlegroups.com
Hello Nick,

The KDF iteration length was changed from 4,000 to 64,000 when going
from the 2.x format to 3.0.0. When using the new 3.x libraries on older
database file formats, it is recommended that you perform a one time
upgrade of the database using the PRAGMA cipher_migrate. An example of
this type of upgrade can be found in our test suite here [1].

1.
https://github.com/sqlcipher/sqlcipher-android-tests/blob/master/src/main/java/net/zetetic/tests/CipherMigrateTest.java
> > an email to sqlcipher+...@googlegroups.com <javascript:>.
> > For more options, visit https://groups.google.com/groups/opt_out
> <https://groups.google.com/groups/opt_out>.
>
> --
> Nick Parker
signature.asc

Nick Danukarjanto

unread,
Dec 16, 2013, 5:33:47 PM12/16/13
to sqlc...@googlegroups.com
That did the trick, thanks for all your help!
Reply all
Reply to author
Forward
0 new messages