|
| 1 | +### Download Source and Binaries |
| 2 | + |
| 3 | +The latest AAR binary package information can be [here](https://www.zetetic.net/sqlcipher/open-source), the source can be found [here](https://github.com/sqlcipher/android-database-sqlcipher). |
| 4 | +<p><a href="https://maven-badges.herokuapp.com/maven-central/net.zetetic/android-database-sqlcipher"><img src="https://maven-badges.herokuapp.com/maven-central/net.zetetic/android-database-sqlcipher/badge.svg"></a></p> |
| 5 | + |
| 6 | +### Compatibility |
| 7 | + |
| 8 | +SQLCipher for Android runs on Android 4–Android 9, for `armeabi`, `armeabi-v7a`, `x86`, `x86_64`, and `arm64_v8a` architectures. |
| 9 | + |
| 10 | +### Contributions |
| 11 | + |
| 12 | +We welcome contributions, to contribute to SQLCipher for Android, a [contributor agreement](https://www.zetetic.net/contributions/) needs to be submitted. All submissions should be based on the `master` branch. |
| 13 | + |
| 14 | +### An Illustrative Terminal Listing |
| 15 | + |
| 16 | +A typical SQLite database in unencrypted, and visually parseable even as encoded text. The following example shows the difference between hexdumps of a standard SQLite database and one implementing SQLCipher. |
| 17 | + |
| 18 | +``` |
| 19 | +~ sjlombardo$ hexdump -C sqlite.db |
| 20 | +00000000 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 |SQLite format 3.| |
| 21 | +… |
| 22 | +000003c0 65 74 32 74 32 03 43 52 45 41 54 45 20 54 41 42 |et2t2.CREATE TAB| |
| 23 | +000003d0 4c 45 20 74 32 28 61 2c 62 29 24 01 06 17 11 11 |LE t2(a,b)$…..| |
| 24 | +… |
| 25 | +000007e0 20 74 68 65 20 73 68 6f 77 15 01 03 01 2f 01 6f | the show…./.o| |
| 26 | +000007f0 6e 65 20 66 6f 72 20 74 68 65 20 6d 6f 6e 65 79 |ne for the money| |
| 27 | +
|
| 28 | +~ $ sqlite3 sqlcipher.db |
| 29 | +sqlite> PRAGMA KEY=’test123′; |
| 30 | +sqlite> CREATE TABLE t1(a,b); |
| 31 | +sqlite> INSERT INTO t1(a,b) VALUES (‘one for the money’, ‘two for the show’); |
| 32 | +sqlite> .quit |
| 33 | +
|
| 34 | +~ $ hexdump -C sqlcipher.db |
| 35 | +00000000 84 d1 36 18 eb b5 82 90 c4 70 0d ee 43 cb 61 87 |.?6.?..?p.?C?a.| |
| 36 | +00000010 91 42 3c cd 55 24 ab c6 c4 1d c6 67 b4 e3 96 bb |.B?..?| |
| 37 | +00000bf0 8e 99 ee 28 23 43 ab a4 97 cd 63 42 8a 8e 7c c6 |..?(#C??.?cB..|?| |
| 38 | +
|
| 39 | +~ $ sqlite3 sqlcipher.db |
| 40 | +sqlite> SELECT * FROM t1; |
| 41 | +Error: file is encrypted or is not a database |
| 42 | +``` |
| 43 | +(example courtesy of SQLCipher) |
| 44 | + |
| 45 | +### Application Integration |
| 46 | + |
| 47 | +We’ve packaged up a very simple SDK for any Android developer to add SQLCipher into their app with the following three steps: |
| 48 | + |
| 49 | +1. Add a [reference](https://search.maven.org/search?q=a:android-database-sqlcipher) to the AAR package: `implementation 'net.zetetic:android-database-sqlcipher:Current.Version.Here@aar'` |
| 50 | +2. Update the package import path from `android.database.sqlite.*` to `net.sqlcipher.database.*` in any source files that reference it. The original `android.database.Cursor` may still be used unchanged. |
| 51 | +3. Initialize the database library and pass a variable argument to the open database method with a password: |
| 52 | + |
| 53 | +``` |
| 54 | +// First initilize the native database libraries with the context |
| 55 | +SQLiteDatabase.loadLibs(this); |
| 56 | +
|
| 57 | +// Request a database connection with passwrod |
| 58 | +SQLiteDatabase.openOrCreateDatabase(databasePath.getAbsolutePath(), password, null); |
| 59 | +``` |
| 60 | + |
| 61 | +An article covering both integration of SQLCipher into an Android application as well as building the source can be found [here](https://www.zetetic.net/sqlcipher/sqlcipher-for-android/). |
| 62 | + |
| 63 | +### Building |
| 64 | + |
| 65 | +In order to build `android-database-sqlcipher` from source you will need both the Android SDK, Gradle, and the Android NDK. We currently recommend using Android NDK version `r15c`, however we plan to update to a newer NDK release when possible. To complete the `make` command, the `ANDROID_NDK_ROOT` environment variable must be defined which should point to your NDK root. Once you have cloned the repo, change directory into the root of the repository and run the following commands: |
| 66 | + |
| 67 | +``` |
| 68 | +# this only needs to be done once |
| 69 | +make init |
| 70 | +
|
| 71 | +# to build the source for debug: |
| 72 | +make build-debug |
| 73 | +# or for a release build: |
| 74 | +make build-release |
| 75 | +``` |
| 76 | + |
| 77 | +### License |
| 78 | + |
| 79 | +The Android support libraries are licensed under Apache 2.0, in line with the Android OS code on which they are based. The SQLCipher code itself is licensed under a BSD-style license from Zetetic LLC. Finally, the original SQLite code itself is in the public domain. |
0 commit comments