Frustrated / FMDB and Sqlcipher

262 views
Skip to first unread message

Nathan187

unread,
Apr 3, 2013, 11:58:55 PM4/3/13
to sqlc...@googlegroups.com
Does anyone have any links to any blog or good tutorial for using FMDB along with sqlcipher?

I can export to an encrypted database but if I need to ever access that database again, I'll get an error saying "file is encrypted or is not a database".

I've tried setting the key via 'setKey', PRAGMA statements and even the sqlite_key function.  Nothing works. 

I've read in blogs and postings, to make sure you're using the sqlcipher version of sqlite but it doesn't mention actually how to do that.

Any help would be appreciated.  Thanks

Stephen Lombardo

unread,
Apr 4, 2013, 9:54:40 AM4/4/13
to sqlc...@googlegroups.com
Hi Nathan,

It's Stephen here, we chatted a bit off list before you subscribed.

The first thing to check is that you have setup your application to use SQLCipher. If you are using SQLCipher Community Edition, there is a full tutorial here at http://sqlcipher.net/ios-tutorial/ on how to setup the application. If you'd prefer to use the Commercial Edition, the setup information is available here http://sqlcipher.net/sqlcipher-binaries-ios-and-osx.

A good way to check whether your application is linked to sqlcipher is to issue a query for "PRAGMA cipher_version;". If it returns a version string then the linking is correct. If it doesn't, then the app is very likely dynamically linking against the system's libsqlite3.

If you are linking against SQLCipher, are successfully exporting an encrypted database from within the application, have verified that the database is actually encrypted, and are getting a version string back, then there might be some other issue at play. In this case, it would be helpful to see an example of the code you are using, perhaps in a gist, to try and see what is going on.

Cheers,
Stephen

Billy Gray

unread,
Apr 4, 2013, 3:29:20 PM4/4/13
to sqlc...@googlegroups.com
Hi Nathan,

Just as a follow-up, I took a quick look at FMDB's handling of the database open call, it looks like no PRAGMAs or other commands are issued (which can interfere if run before a key is set depending on whether they attempt to access the database structure, e.g. '.schema') which you can see here. This means that you should be able to issue "PRAGMA key" or call sqlite3_key right after the open call provided SQLCipher is properly linked into your application as Stephen mentioned.

Also, have a look at the setKey: implementation—you can see that if the SQLITE_HAS_CODEC flag is not defined at compile time, this method will just return the BOOL value NO. -DSQLITE_HAS_CODEC needs to be defined in your project's Other C Flags build setting, as documented in the tutorials Stephen linked, you might want to make sure you didn't miss that step.

Cheers,
Billy Gray


--

---
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.





--
Team Zetetic
http://zetetic.net

Nathan187

unread,
Apr 14, 2013, 5:42:00 PM4/14/13
to sqlc...@googlegroups.com
Stephen and Billy

There's a saying from my state (which I won't mention so I won't offend other people from there)

"You can't fix stupid"....

or better yet....RTFM, Nathan!!!

Thanks for your patience and help.
Reply all
Reply to author
Forward
0 new messages