add pragma cipher_default_use_hmac to toggle global HMAC setting
[sqlcipher.git] / README
blob1b0a46191f570cc012fcb517435c30f59b896c62
1 == SQLCipher ==
3 SQLCipher is an SQLite extension that provides transparent 256-bit AES encryption of 
4 database files. Pages are encrypted before being written to disk and are decrypted 
5 when read back. Due to the small footprint and great performance it’s ideal for 
6 protecting embedded application databases and is well suited for mobile development.
8 The official SQLCipher software site is http://sqlcipher.net
10 SQLCipher was initially developed by Stephen Lombardo at Zetetic LLC 
11 (sjlombardo@zetetic.net) as the encrypted database layer for Strip, 
12 an iPhone data vault and password manager (http://getstrip.com).   
14 [Features]
16 - Fast performance with as little as 5-15% overhead for encryption on many operations
17 - 100% of data in the database file is encrypted
18 - Good security practices (CBC mode, key derivation)
19 - Zero-configuration and application level cryptography
20 - Algorithms provided by the peer reviewed OpenSSL crypto library.
22 [Compiling]
24 Building SQLCipher is almost the same as compiling a regular version of 
25 SQLite with two small exceptions: 
27  1. You must define SQLITE_HAS_CODEC and SQLITE_TEMP_STORE=2 when building sqlcipher
28  2. You need to link against a OpenSSL's libcrypto 
30 Example Static linking (replace /opt/local/lib with the path to libcrypto.a)
32   $ ./configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC" \
33     LDFLAGS="/opt/local/lib/libcrypto.a"
34   $ make
36 Example Dynamic linking
38   $ ./configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC" \
39     LDFLAGS="-lcrypto"
40   $ make
42 [Encrypting a database]
44 To specify an encryption passphrase for the database via the SQL interface you 
45 use a pragma. The passphrase you enter is passed through PBKDF2 key derivation to
46 obtain the encryption key for the database 
48   PRAGMA key = 'passphrase';
50 Alternately, you can specify an exact byte sequence using a blob literal. If you
51 use this method it is your responsibility to ensure that the data you provide a
52 64 character hex string, which will be converted directly to 32 bytes (256 bits) of 
53 key data without key derivation.
55   PRAGMA key = "x'2DD29CA851E7B56E4697B0E1F08507293D761A05CE4D1B628663F411A8086D99'";
57 To encrypt a database programatically you can use the sqlite3_key function. 
58 The data provided in pKey is converted to an encryption key according to the 
59 same rules as PRAGMA key. 
62   int sqlite3_key(sqlite3 *db, const void *pKey, int nKey);
64 PRAGMA key or sqlite3_key should be called as the first operation when a database is open.
66 [Changing a database key]
68 To change the encryption passphrase for an existing database you may use the rekey pragma
69 after you've supplied the correct database password;
71   PRAGMA key = 'passphrase'; -- start with the existing database passphrase
72   PRAGMA rekey = 'new-passphrase'; -- rekey will reencrypt with the new passphrase
74 The hexrekey pragma may be used to rekey to a specific binary value
76   PRAGMA rekey = "x'2DD29CA851E7B56E4697B0E1F08507293D761A05CE4D1B628663F411A8086D99'";
78 This can be accomplished programtically by using sqlite3_rekey;
79   
80   sqlite3_rekey(sqlite3 *db, const void *pKey, int nKey)
82 [Support]
84 The primary avenue for support and discussions is the SQLCipher users mailing list:
86 http://groups.google.com/group/sqlcipher
88 Issues or support questions on using SQLCipher should be entered into the 
89 GitHub Issue tracker:
91 http://github.com/sjlombardo/sqlcipher/issues
93 Please DO NOT post issues, support questions, or other problems to blog 
94 posts about SQLCipher as we do not monitor them frequently.
96 If you are using SQLCipher in your own software please let us know at 
97 support@zetetic.net!
99 [License]
101 Copyright (c) 2008, ZETETIC LLC
102 All rights reserved.
104 Redistribution and use in source and binary forms, with or without
105 modification, are permitted provided that the following conditions are met:
106     * Redistributions of source code must retain the above copyright
107       notice, this list of conditions and the following disclaimer.
108     * Redistributions in binary form must reproduce the above copyright
109       notice, this list of conditions and the following disclaimer in the
110       documentation and/or other materials provided with the distribution.
111     * Neither the name of the ZETETIC LLC nor the
112       names of its contributors may be used to endorse or promote products
113       derived from this software without specific prior written permission.
115 THIS SOFTWARE IS PROVIDED BY ZETETIC LLC ''AS IS'' AND ANY
116 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
117 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
118 DISCLAIMED. IN NO EVENT SHALL ZETETIC LLC BE LIABLE FOR ANY
119 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
120 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
121 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
122 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
123 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
124 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
126 == End SQLCipher ==
128 This directory contains source code to 
130     SQLite: An Embeddable SQL Database Engine
132 To compile the project, first create a directory in which to place
133 the build products.  It is recommended, but not required, that the
134 build directory be separate from the source directory.  Cd into the
135 build directory and then from the build directory run the configure
136 script found at the root of the source tree.  Then run "make".
138 For example:
140     tar xzf sqlite.tar.gz    ;#  Unpack the source tree into "sqlite"
141     mkdir bld                ;#  Build will occur in a sibling directory
142     cd bld                   ;#  Change to the build directory
143     ../sqlite/configure      ;#  Run the configure script
144     make                     ;#  Run the makefile.
145     make install             ;#  (Optional) Install the build products
147 The configure script uses autoconf 2.61 and libtool.  If the configure
148 script does not work out for you, there is a generic makefile named
149 "Makefile.linux-gcc" in the top directory of the source tree that you
150 can copy and edit to suit your needs.  Comments on the generic makefile
151 show what changes are needed.
153 The linux binaries on the website are created using the generic makefile,
154 not the configure script.  The windows binaries on the website are created
155 using MinGW32 configured as a cross-compiler running under Linux.  For 
156 details, see the ./publish.sh script at the top-level of the source tree.
157 The developers do not use teh configure script.
159 SQLite does not require TCL to run, but a TCL installation is required
160 by the makefiles.  SQLite contains a lot of generated code and TCL is
161 used to do much of that code generation.  The makefile also requires
162 AWK.
164 Contacts:
166    http://www.sqlite.org/