SQLcipher Guide
SQLCipher is based on SQLite, and thus, the majority of the accessible API is identical to the C/C++ interface for SQLite 3. However, SQLCipher does add a number of security specific extensions in the form of PRAGMAs, SQL Functions and C Functions.
Building SQLCipher from Source
Clone the SQLCipher repository by running the following command:
1$ git clone https://github.com/sqlcipher/sqlcipher.gitNavigate to the cloned repository:
1$ cd sqlcipherConfigure the build with the following command:
1$ ./configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC -DSQLITE_TEMP_STORE=2" LDFLAGS="-lcrypto"Build SQLCipher by running the make command:
1$ makeOptional: If you want to perform a system-wide installation of SQLCipher, run the following command:
1$ make install
Take note of the output of the make install command, specifically the following lines:
libtool: install: /usr/bin/install -c .libs/libsqlcipher.a /usr/local/lib/libsqlcipher.a/usr/bin/install -c -m 0644 sqlite3.h /usr/local/include/sqlcipher
These lines indicate the folders where the SQLCipher headers and library are installed, which are necessary when building a C project.
Building a Minimal C Project Example
Create a file named SQLite_example.c and add the following lines:
| |
Build the example by running the following command in the terminal:
| |
For example, if you extracted the paths from the output of the make install command:
| |
Make sure that the SQLCipher library is in the system-wide library path. For example, on (Arch)Linux, you can set the LD_LIBRARY_PATH environment variable:
| |
Finally, run your test code:
| |
Decrypt the database to a plaintext database
Use command to decrypt the database:
| |
Or, use SQliteStudio:
That’s it! You have successfully built SQLCipher from source and created a minimal C project example using SQLCipher.
