I’ve tried multiple solutions to browse SqlCipher
Databases and the only one that seemed to work properly was [DB Sqlite Browser](DB Browser for SQLite (sqlitebrowser.org)) with easy GUI to get into the db. but … the overall experience of that application didn’t really satisfy me!
I knew DBeaver from long time ago, and i wondered if i can use it with SQLCipher, but it was surprisingly a shock that it doesn’t work directly, but with a couple of hours of researching and trying different methods i finally came up with a way to configure it Out-of-the box to make it work!
The reason I wrote this gist was to help others who have the same issue as it seems there is no guide to show how to do so!
So Let's Go !
- head to https://dbeaver.io/
- download the one that suits your OS
- Install !
- head to https://github.com/Willena/sqlite-jdbc-crypt/releases and download the latest
sqlite-jdbc-<version>.jar
. - copy that file in a safe place on your pc that you DON'T ACCIDENTALY REMOVE
Well, there are multiple versions of SQLCipher and in this gist i'll target only SqlCipher V3 but it's the same Idea once you grasp it!
- From Database Menu --> Open DriverManager
- Hit New, and now let‘s configure it
- Driver Name = SqlCipherV3 (or any name you’d like)
- Driver Type, Select Generic
- Class Name =
org.sqlite.JDBC
- URL Template =
jdbc:sqlite:{file}
The rest are not mandatory, feel free to setup them up on your own!
Remember the .jar
file that we’ve downloaded recently?
If your answer was no, please have a look [Getting the right driver](#Getting-the-right-driver-to-get the-Job-done)
If your answer was yes, Let‘s continue
- Click
Add File
and Select that.jar
file - Click
Find Class
and selectorg.sqlite.JDBC
Here comes the most important part, make sure that you’ve configured that one properly!
To Add a property, Right-Click and press Add
Key | Value |
---|---|
cipher | sqlcipher |
fast_kdf_iter | 2 |
hmac_algorithm | 0 |
hmac_pgno | 1 |
hmac_salt_mask | 0x3a |
hmac_user | 1 |
kdf_iter | 64000 |
legacy | 3 |
legacy_page_size | 1024 |
There are one more PRAGMA which is called key
and it is used to pass a passphrase that’s used to decrypt your db, but we won’t set it here as it differs from a database to another
For different version parameters of SqlCipher visit: https://utelle.github.io/SQLite3MultipleCiphers/docs/ciphers/cipher_sqlcipher/ and actually i’ve acquired the above one from there!
Parameter | v4 | v3 | v2 | v1 |
---|---|---|---|---|
kdf_iter |
256000 | 64000 | 4000 | 4000 |
fast_kdf_iter |
2 | 2 | 2 | 2 |
hmac_use |
1 | 1 | 1 | 0 |
hmac_pgno |
1 | 1 | 1 | n/a |
hmac_salt_mask |
0x3a | 0x3a | 0x3a | n/a |
legacy |
4 | 3 | 2 | 1 |
legacy_page_size |
4096 | 1024 | 1024 | 1024 |
kdf_algorithm |
2 | 0 | 0 | 0 |
hmac_algorithm |
2 | 0 | 0 | 0 |
plaintext_header_size |
0 | n/a | n/a | n/a |
Note: -
- for
n/a
values don’t enter anything!- V indicates the SqlCipher Version!
- From Database Menu —> Select New Database Connection
- Search for SqlCipherV3 (the one we created recently) and press Next
- Click Browse and Select your SqlCipher Database file
- In Driver properties tab make sure that your defaults has been set correctly
- In
Key
Property double click the Value and Enter your Passphrase
- In
- Test Connection, Voila!
- Press Finish
If you encountered any problem, please feel free to comment below and I’ll gladly help!
I spend quite some time trying all the cipher versions. In the first table, where the settings for v3 are dispalyed, you have hmac_user as key, but I think it should be hmac_use.
In the second table, where all versions are displayed, the key cipher with value sqlcipher was omitted. This was eventually the problem for me, I didn't add this key for all the other versions because I copy & pasted the whole table. When I also added the cipher key, my v4 was working.
Tested with SQLite-jdbc-3.41.2.0