# SQLCipher Support added to 'DB Browser for SQLite'

**URL:** <https://discuss.zetetic.net/t/sqlcipher-support-added-to-db-browser-for-sqlite/243>\
**Category:** SQLCipher\
**Created:** [November 6, 2014, 8:11pm UTC](https://discuss.zetetic.net/t/sqlcipher-support-added-to-db-browser-for-sqlite/243 "2014-11-06T20:11:20Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![justinclift](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/justinclift/32/89_2.png) [@justinclift](https://discuss.zetetic.net/u/justinclift)\
**Post date:** [November 6, 2014, 8:11pm UTC](https://discuss.zetetic.net/t/sqlcipher-support-added-to-db-browser-for-sqlite/243/1 "2014-11-06T20:11:20Z")

</div>

Hi all,

The DB Browser for SQLite project is adding support for SQLCipher in our next release.

(we were previously known as “SQLite Database Browser” which is probably more recognised :\>)

An initial build for MacOS X (10.6-10.10) that includes SQLCipher support is here:

&nbsp; &nbsp; [http://mirror.salasaga.org/sqlitebrowser/onceoffs/sqlitebrowser\_201411051855.dmg](http://mirror.salasaga.org/sqlitebrowser/onceoffs/sqlitebrowser_201411051855.dmg)

Is anyone around with time to test it and report back success/failure and anything else relevant?

Our GitHub Issue tracker:

&nbsp; &nbsp; [https://github.com/sqlitebrowser/sqlitebrowser/issues](https://github.com/sqlitebrowser/sqlitebrowser/issues)

Regards and best wishes,

Justin Clift

---

<div class="post-metadata">

**Author:** ![developernotes](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/developernotes/32/1309_2.png) [@developernotes](https://discuss.zetetic.net/u/developernotes)\
**Post date:** [November 6, 2014, 11:07pm UTC](https://discuss.zetetic.net/t/sqlcipher-support-added-to-db-browser-for-sqlite/243/2 "2014-11-06T23:07:17Z")

</div>

Hi Justin,

Thanks for sharing your project - we are glad to see you are working on  
integrating SQLCipher!

---

<div class="post-metadata">

**Author:** ![justinclift](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/justinclift/32/89_2.png) [@justinclift](https://discuss.zetetic.net/u/justinclift)\
**Post date:** [November 7, 2014, 2:12am UTC](https://discuss.zetetic.net/t/sqlcipher-support-added-to-db-browser-for-sqlite/243/3 "2014-11-07T02:12:45Z")

</div>

You’re welcome. 😃

We’re pretty driven by user requests, and this is one of our older ones:

&nbsp; &nbsp; [https://github.com/sqlitebrowser/sqlitebrowser/issues/12](https://github.com/sqlitebrowser/sqlitebrowser/issues/12)

In our limited testing so far (on MacOS and Linux) it seems to be working fine.

We’re not exactly sure how to cross compile it all for Win32 yet, but we’ll figure it out in the next month or so. Each release of DB Browser for SQLite (every 6-8 weeks) gets ~200k downoads, and about 80% of that is Windows. So, we’ll need to figure it out.

Hopefully this all helps spread the usage of SQLCipher a bunch. 😃

---

<div class="post-metadata">

**Author:** ![wgray](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/wgray/32/843_2.png) [@wgray](https://discuss.zetetic.net/u/wgray)\
**Post date:** [November 7, 2014, 3:17pm UTC](https://discuss.zetetic.net/t/sqlcipher-support-added-to-db-browser-for-sqlite/243/4 "2014-11-07T15:17:03Z")

</div>

Hi Justin, this may sound a little slow on my part, but would you mind telling us how to enable the SQLCipher support in order to help you test the new feature? When I open an existing database I don’t see any options to specify a key or other SQLCipher settings used for opening the DB, nor do I see the options when I go to create a new database and wish to enable encryption. But they’re in the screenshots on your Github issue tracker, so I’m sure they’re there and I’m just looking in the wrong place.

Thanks!

---

<div class="post-metadata">

**Author:** ![justinclift](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/justinclift/32/89_2.png) [@justinclift](https://discuss.zetetic.net/u/justinclift)\
**Post date:** [November 7, 2014, 7:05pm UTC](https://discuss.zetetic.net/t/sqlcipher-support-added-to-db-browser-for-sqlite/243/5 "2014-11-07T19:05:59Z")

</div>

No worries at all.

Are you using the MacOS .dmg file, or are you using a different OS?

If you’re compiling on a different OS (eg Linux or FreeBSD), you’ll need to compile with:

```
$ qmake CONFIG+=sqlcipher
$ make

```

Instead of:

```
$ qmake
$ make

```

We need to update the instructions with that now I think about it… Oops. 😉

With the MacOS .dmg file, there should be an option in the file menu to “Set Encryption”. That’s used to set the password and page size to encrypt the database.

When opening an encrypted database, the dialog asking for the decryption password and page size should (in theory) automatically pop up.

If something in the above isn’t doing what it’s supposed to, we’ll need to fix it. 😃

---

<div class="post-metadata">

**Author:** ![sjlombardo](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/sjlombardo/32/3_2.png) [@sjlombardo](https://discuss.zetetic.net/u/sjlombardo)\
**Post date:** [November 10, 2014, 7:43pm UTC](https://discuss.zetetic.net/t/sqlcipher-support-added-to-db-browser-for-sqlite/243/6 "2014-11-10T19:43:29Z")

</div>

Hi @justinclift, thanks for your work to integrate SQLCipher!

I just tried out the Mac version, it looks great. I noticed though that it seems to only inconsistently open databases I create with the command line tool. It seems like the first few tries fail, but after that, it ends up opening the database. I can’t seem to narrow down any specific criteria. Have you noticed this before? If you’d like, I can send over a test database.

Also, with regard to the page size, is there a reason that 4096 is set as the default? SQLCipher uses 1024 as the default page size, and the vast majority of databases are created using that page size.

---

<div class="post-metadata">

**Author:** ![justinclift](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/justinclift/32/89_2.png) [@justinclift](https://discuss.zetetic.net/u/justinclift)\
**Post date:** [November 10, 2014, 7:59pm UTC](https://discuss.zetetic.net/t/sqlcipher-support-added-to-db-browser-for-sqlite/243/7 "2014-11-10T19:59:35Z")

</div>

Ahhh, I haven’t noticed that inconsistency before. If you could either email that test database to me ([justin@postgresql.org](mailto:justin@postgresql.org)), or chuck it somewhere online for download, that would be awesome.

With the 4096 default, I’m not sure (yet), as I didn’t write the code for our SQLCipher support. I’ll point Martin at this thread and either cut-n-paste responses back (or he can join and reply directly). 🙂

---

<div class="post-metadata">

**Author:** ![justinclift](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/justinclift/32/89_2.png) [@justinclift](https://discuss.zetetic.net/u/justinclift)\
**Post date:** [November 10, 2014, 9:02pm UTC](https://discuss.zetetic.net/t/sqlcipher-support-added-to-db-browser-for-sqlite/243/8 "2014-11-10T21:02:30Z")

</div>

@sjlombardo Martin’s response re the 4096 default:

> The reason for the default page size being 4096 is that this seems to be the  
> default value used by the sqlcipher Debian package which I’ve used for  
> testing. Maybe they’ve changed the default value for whatever reason… But if  
> 1024 is the ‘official’ default value I’ll change it to that soon.

Is 1024 definitely the ‘official’ SQLCipher default? If so, Martin sounds happy to change it. 😄

With the inconsistency in opening databases, the test database you’re using would really help. 😉

---

<div class="post-metadata">

**Author:** ![developernotes](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/developernotes/32/1309_2.png) [@developernotes](https://discuss.zetetic.net/u/developernotes)\
**Post date:** [November 10, 2014, 9:40pm UTC](https://discuss.zetetic.net/t/sqlcipher-support-added-to-db-browser-for-sqlite/243/9 "2014-11-10T21:40:44Z")

</div>

Hi Justin,

I just took a peek at SQLCipher 3.2.0 on Debian installed via apt-get  
and the default cipher\_page\_size value is 1024. It would be beneficial  
to keep with the default value of 1024, allowing for easy portability  
for users. Thanks for getting back to us so quickly!

---

<div class="post-metadata">

**Author:** ![justinclift](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/justinclift/32/89_2.png) [@justinclift](https://discuss.zetetic.net/u/justinclift)\
**Post date:** [November 11, 2014, 12:42am UTC](https://discuss.zetetic.net/t/sqlcipher-support-added-to-db-browser-for-sqlite/243/10 "2014-11-11T00:42:21Z")

</div>

@developernotes @sjlombardo No worries. 😉

Try this one instead, it’s updated to use 1024 as the default value, and has some workaround code that Martin says should fix the inconsistency.

&nbsp; &nbsp; [http://mirror.salasaga.org/sqlitebrowser/onceoffs/sqlitebrowser-sqlcipher\_201411101930.dmg](http://mirror.salasaga.org/sqlitebrowser/onceoffs/sqlitebrowser-sqlcipher_201411101930.dmg)

Lets see how that goes. 😊

---

<div class="post-metadata">

**Author:** ![mkleusberg](https://avatars.discourse-cdn.com/v4/letter/m/e19adc/32.png) [@mkleusberg](https://discuss.zetetic.net/u/mkleusberg)\
**Post date:** [November 11, 2014, 9:17am UTC](https://discuss.zetetic.net/t/sqlcipher-support-added-to-db-browser-for-sqlite/243/11 "2014-11-11T09:17:34Z")

</div>

Hi guys! My name is Martin and I’m one of the developers of DB Browser for SQLite. Thanks everybody for your kind words and especially @sjlombardo for his feedback.  
So I think I’ve found this inconsistency in opening an encrypted file you were talking about. I could reproduce this by creating a file using the sqlcipher command line tool like this:  
$ sqlcipher test.db

> pragma key = ‘test’;  
> create table test(a int, b int);  
> .quit

So the page size is left at its default value - which indeed is 1024 😉

Now trying to open this database wouldn’t work if I use the correct password AND page size but only if I first use the correct password but incorrect page size and only then the correct password and correct page size.  
I’ve spent a bit of time debugging this but couldn’t find a reason for this behaviour, so what I did was adding exactly that workaround to the program (see [cipher: Fix opening SQLCipher DBs using page size 1024 · sqlitebrowser/sqlitebrowser@a455215 · GitHub](https://github.com/sqlitebrowser/sqlitebrowser/commit/a4552152af73569d57590a4a3f583727b706584c)) but I’ve no idea how this fixes it even though it does 😕  
But maybe some of you can help me out here 🙂

---

<div class="post-metadata">

**Author:** ![developernotes](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/developernotes/32/1309_2.png) [@developernotes](https://discuss.zetetic.net/u/developernotes)\
**Post date:** [November 13, 2014, 2:27pm UTC](https://discuss.zetetic.net/t/sqlcipher-support-added-to-db-browser-for-sqlite/243/12 "2014-11-13T14:27:43Z")

</div>

Hello Martin,

Taking a quick look at your commit, I believe the issue is two fold.  
First, you will need to key the database first, immediately following  
that you will want to perform the PRAGMA cipher\_page\_size. The  
reasoning is because the cipher context within SQLCipher is not created  
until the database has been keyed. Secondly, you will want to adjust  
the cipher\_page\_size to 1024 by default. Could you try adjusting that  
and let us know your results? Thanks!

---

<div class="post-metadata">

**Author:** ![sjlombardo](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/sjlombardo/32/3_2.png) [@sjlombardo](https://discuss.zetetic.net/u/sjlombardo)\
**Post date:** [November 13, 2014, 9:43pm UTC](https://discuss.zetetic.net/t/sqlcipher-support-added-to-db-browser-for-sqlite/243/13 "2014-11-13T21:43:37Z")

</div>

Hi Martin, thanks so much for working on this, and looking into the issue I reported!

I was taking a look at the code here [https://github.com/sqlitebrowser/sqlitebrowser/blob/master/src/sqlitedb.cpp#L75](https://github.com/sqlitebrowser/sqlitebrowser/blob/master/src/sqlitedb.cpp#L75) and I think the problem is that, after the execution of the select from sqlite\_master, the database handle is an inconsistent state (i.e. it tried to open the database and failed). Flipping around the page sizes is resetting things internally, allowing it to open, but there could be other lurking inconsistencies.

I don’t have a working build environment for the DB Browser for SQLite, but I would suggest an alternate approach for this:

First, try to open database, and select from sqlite master. If it fails, and encryption is enabled:

1. prompt for the password
2. sqlite3\_close the database handle
3. call sqlite3\_open to open it cleanly
4. call sqlite3\_key with the password
5. if the page size entered into the prompt is not 1024, call sqlite3\_exec with pragma page\_size
6. select from sqlite master to verify that the database is readable

By closing the database and then doing a clean open/key/select sequence everything should be kept in a consistent state. Let me know what you think. Thanks!

---

<div class="post-metadata">

**Author:** ![mkleusberg](https://avatars.discourse-cdn.com/v4/letter/m/e19adc/32.png) [@mkleusberg](https://discuss.zetetic.net/u/mkleusberg)\
**Post date:** [November 14, 2014, 12:02pm UTC](https://discuss.zetetic.net/t/sqlcipher-support-added-to-db-browser-for-sqlite/243/14 "2014-11-14T12:02:31Z")

</div>

Thank you both for helping me out here! It’s making a lot more sense now 🙂 I’ve just pushed a commit which fixes this properly so that sqlite3\_key is always called as the first operation on the database handle and it works like a charm.  
Also I’ve set the default cipher page size to 1024 a few days ago. I think the other issue probably made me think it wasn’t 1024 on my system… It’s all kind of obvious in hindsight now 😉 I hope we can provide a fresh MacOS X and maybe even a Windows build with the new fix soon!

---

<div class="post-metadata">

**Author:** ![justinclift](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/justinclift/32/89_2.png) [@justinclift](https://discuss.zetetic.net/u/justinclift)\
**Post date:** [November 14, 2014, 5:42pm UTC](https://discuss.zetetic.net/t/sqlcipher-support-added-to-db-browser-for-sqlite/243/15 "2014-11-14T17:42:59Z")

</div>

Excellent stuff. 😄

Looks like this is in a decent state now, so just now updated the OSX nightly build script to also generate binaries with SQLCipher support. Today’s builds:

&nbsp; &nbsp; [http://mirror.salasaga.org/sqlitebrowser/nightly/sqlitebrowser-sqlcipher\_20141114.dmg](http://mirror.salasaga.org/sqlitebrowser/nightly/sqlitebrowser-sqlcipher_20141114.dmg)  
&nbsp; &nbsp; [http://mirror.salasaga.org/sqlitebrowser/nightly/sqlitebrowser\_20141114.dmg](http://mirror.salasaga.org/sqlitebrowser/nightly/sqlitebrowser_20141114.dmg)

Tested the SQLCipher one on an OSX 10.8 desktop, and it opened and browsed an encrypted test database fine. (didn’t really try much else though)

Next, I guess we need to figure out our cross-compile Windows build support. (Windows is still 80% of our download #'s)

Anyone interested in getting SQLCipher into MXE ([http://mxe.cc](http://mxe.cc))? 😉

---

<div class="post-metadata">

**Author:** ![justinclift](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/justinclift/32/89_2.png) [@justinclift](https://discuss.zetetic.net/u/justinclift)\
**Post date:** [February 8, 2015, 4:42pm UTC](https://discuss.zetetic.net/t/sqlcipher-support-added-to-db-browser-for-sqlite/243/16 "2015-02-08T16:42:09Z")

</div>

Oops, forgot to mention it previously… but this is now released and actively being used:

[https://github.com/sqlitebrowser/sqlitebrowser/releases/tag/v3.5.1](https://github.com/sqlitebrowser/sqlitebrowser/releases/tag/v3.5.1)

(actually with v3.5.0 from a week ago)

Hope that helps. 😄

---

<div class="post-metadata">

**Author:** ![wgray](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/wgray/32/843_2.png) [@wgray](https://discuss.zetetic.net/u/wgray)\
**Post date:** [February 9, 2015, 3:43pm UTC](https://discuss.zetetic.net/t/sqlcipher-support-added-to-db-browser-for-sqlite/243/17 "2015-02-09T15:43:54Z")

</div>

Congratulations, @justinclift!

---

<div class="post-metadata">

**Author:** ![soliton](https://avatars.discourse-cdn.com/v4/letter/s/cc9497/32.png) [@soliton](https://discuss.zetetic.net/u/soliton)\
**Post date:** [February 10, 2015, 11:14pm UTC](https://discuss.zetetic.net/t/sqlcipher-support-added-to-db-browser-for-sqlite/243/18 "2015-02-10T23:14:27Z")

</div>

Pardon my ignorance here. I am not sure which version I am supposed to compile using qmake. Is it the DMG one or the source one?  
I have just downloaded version 3.5.1 (source code) and compiled it alright using:

```
cmake.

```

and

```
make

```

as per usual instruction [here](https://github.com/sqlitebrowser/sqlitebrowser/blob/master/BUILDING.md)  
At no point have I ever used qmake.  
I can open databases but I do not get prompted for a password when I open an encrypted one.

I am using Linux Mint 17 with SQL Cipher installed.  
Where did I go wrong?

---

<div class="post-metadata">

**Author:** ![justinclift](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/justinclift/32/89_2.png) [@justinclift](https://discuss.zetetic.net/u/justinclift)\
**Post date:** [February 10, 2015, 11:40pm UTC](https://discuss.zetetic.net/t/sqlcipher-support-added-to-db-browser-for-sqlite/243/19 "2015-02-10T23:40:54Z")

</div>

Ahhh, it sounds like you’re close. The instructions for compiling with SQLCipher support steps are a bit further down that [BUILDING.md](http://BUILDING.md) page.

I haven’t personally tried them on Linux, so am a bit unsure though. (I do OSX stuff)

If cmake isn’t picking up SQLCipher, then Martin or one of the SQLCipher Community here will hopefully know how to resolve that.

Btw, the .dmg file is an OSX binary, so probably not useful for you. Compiling from the 3.5.1 tarball would be the go. 😄

---

<div class="post-metadata">

**Author:** ![soliton](https://avatars.discourse-cdn.com/v4/letter/s/cc9497/32.png) [@soliton](https://discuss.zetetic.net/u/soliton)\
**Post date:** [February 11, 2015, 11:32am UTC](https://discuss.zetetic.net/t/sqlcipher-support-added-to-db-browser-for-sqlite/243/20 "2015-02-11T11:32:04Z")

</div>

Thumbs up Justin! 😄  
I re-compiled it following the instruction and it works great!  
Obviously, I didn’t scroll down enough to spot the SQLCipher paragraph 😉

Keep up the good work: you have a great piece of software here!

Marco

[Next page](https://discuss.zetetic.net/t/sqlcipher-support-added-to-db-browser-for-sqlite/243.md?page=2)
