SQLCipher is Full Database Encryption for Sqlite. It’s supporting iOS and Mac also.


First you need to pull from github and need to compile ourself.

$ git clone https://github.com/sqlcipher/sqlcipher.git
$ cd sqlcipher
$ ./configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC" LDFLAGS="-lcrypto"
$ make
$ sudo make install

Check sqlcipher ,

$ which sqlcipher

Create Database with sqlcipher,

$ touch encrypted.db
$ sqlcipher encrypted.db
sqlite> PRAGMA KEY='MyKey';
sqlite> CREATE TABLE t1(a,b);
sqlite> INSERT INTO t1(a,b) VALUES ('one for the money', 'two for the show');
sqlite> .exit

Let try to open with sqlite3

$ sqlite3 encrypted.db
sqlite> SELECT * FROM t1;
Error: file is encrypted or is not a database
sqlite> .exit

Let try to open with sqlcipher

$ sqlcipher test.db
sqlite> PRAGMA KEY='MyKey';
sqlite> SELECT * FROM t1;
one for the money|two for the show

For using with iOS , you can read the detail tutorial at http://sqlcipher.net/ios-tutorial/.

comments powered byDisqus