Skip to content

Commit 5b4d50c

Browse files
committed
updated documentation on how to build and use sqlite-cipher in README
1 parent b185f3b commit 5b4d50c

File tree

1 file changed

+47
-10
lines changed

1 file changed

+47
-10
lines changed

README

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,59 @@
1-
== SQLite Cipher Introduction ==
1+
== SQLite Cipher ==
22

33
SQLite Cipher is an SQLite extension that provides transparent 256 bit AES encryption of database files.
44
Pages are encrypted before being written to disk and are decrypted when read back.
55

66
Encryption is provided by the OpenSSL crypto library.
77

8-
Static linking (replace /opt/local/lib with the path to libcrypto.a)
9-
./configure --disable-amalgamation CFLAGS="-DSQLITE_HAS_CODEC" LDFLAGS="/opt/local/lib/libcrypto.a"
10-
make
11-
12-
Dynamic linking
13-
./configure --disable-amalgamation CFLAGS="-DSQLITE_HAS_CODEC -lcrypto"
14-
make
15-
168
SQLite Cipher was developed by Stephen Lombardo at Zetetic LLC.
179
sjlombardo at zetetic.net
1810
http://zetetic.net
1911

12+
[Compiling]
13+
14+
Building SQLite Cipher is almost the same as compiling a regular version of SQLite with three small exceptions:
15+
16+
1. building via 'amalgamation' isn't supported (where all sqlite source is merged into one file)
17+
2. you must define SQLITE_HAS_CODEC
18+
3. You need to link against a OpenSSL's libcrypto with sha256 support compiled in
19+
20+
Example Static linking (replace /opt/local/lib with the path to libcrypto.a)
21+
22+
./configure --disable-amalgamation CFLAGS="-DSQLITE_HAS_CODEC" LDFLAGS="/opt/local/lib/libcrypto.a"
23+
make
24+
25+
Example Dynamic linking
26+
27+
./configure --disable-amalgamation CFLAGS="-DSQLITE_HAS_CODEC -lcrypto"
28+
make
29+
30+
[Encrypting a database]
31+
32+
To specify an encryption passphrase for the database you can use a pragma. The passphrase
33+
you enter is hashed using sha256 and the result is used as the encryption key for the
34+
database.
35+
36+
PRAGMA key = 'passphrase';
37+
38+
Alternately, you can specify an exact byte sequence using a blob literal. If you
39+
use this method it is your responsibility to ensure that the data you provide a
40+
64 character hex string, which will be converted directly to 32 bytes (256 bits) of
41+
key data.
42+
43+
PRAGMA key = "x'2DD29CA851E7B56E4697B0E1F08507293D761A05CE4D1B628663F411A8086D99'";
44+
45+
To encrypt a database programatically you can use the sqlite3_key function. The data provided
46+
in pKey is converted to an encryption key according to the same rules as PRAGMA key.
47+
48+
int sqlite3_key(sqlite3 *db, const void *pKey, int nKey);
49+
50+
PRAGMA key or sqlite3_key should be called as the first operation when a database is open.
51+
52+
Note: It is not currently possible to change the encryption key once a database is created. We're
53+
working on implementing rekey functionality.
54+
55+
[License]
56+
2057
This code is released under the same public domain terms as SQLite itself.
2158

2259
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
@@ -27,7 +64,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2764
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2865
THE SOFTWARE.
2966

30-
== End Introduction ==
67+
== End SQLite Cipher ==
3168

3269
This directory contains source code to
3370

0 commit comments

Comments
 (0)