{"id":13482837,"url":"https://github.com/sqlcipher/android-database-sqlcipher","last_synced_at":"2025-05-14T11:08:59.132Z","repository":{"id":42136392,"uuid":"1466080","full_name":"sqlcipher/android-database-sqlcipher","owner":"sqlcipher","description":"Android SQLite API based on SQLCipher","archived":false,"fork":false,"pushed_at":"2023-08-31T20:35:48.000Z","size":74540,"stargazers_count":2783,"open_issues_count":29,"forks_count":567,"subscribers_count":116,"default_branch":"master","last_synced_at":"2025-04-11T22:59:16.902Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.zetetic.net/sqlcipher/sqlcipher-for-android/","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sqlcipher.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2011-03-11T00:11:37.000Z","updated_at":"2025-04-11T11:36:43.000Z","dependencies_parsed_at":"2023-02-09T16:45:54.566Z","dependency_job_id":"358bf1fb-5b1a-4df9-bf86-3685da0d68ff","html_url":"https://github.com/sqlcipher/android-database-sqlcipher","commit_stats":null,"previous_names":[],"tags_count":50,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sqlcipher%2Fandroid-database-sqlcipher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sqlcipher%2Fandroid-database-sqlcipher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sqlcipher%2Fandroid-database-sqlcipher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sqlcipher%2Fandroid-database-sqlcipher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sqlcipher","download_url":"https://codeload.github.com/sqlcipher/android-database-sqlcipher/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254129484,"owners_count":22019628,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T17:01:05.948Z","updated_at":"2025-05-14T11:08:59.110Z","avatar_url":"https://github.com/sqlcipher.png","language":"Java","funding_links":[],"categories":["Java","Index","Libs","Database"],"sub_categories":["Security","\u003cA NAME=\"Orm\"\u003e\u003c/A\u003eOrm"],"readme":"### Deprecated Library\n\nThe `android-database-sqlcipher` project has been [officially deprecated](https://www.zetetic.net/blog/2023/08/31/sqlcipher-4.5.5-release#sqlcipher-android-455). The long-term replacement is [`sqlcipher-android`](https://github.com/sqlcipher/sqlcipher-android). Instructions for migrating from `android-database-sqlcipher` to `sqlcipher-android`may be found [here](https://www.zetetic.net/sqlcipher/sqlcipher-for-android-migration/).\n\n\n### Download Source and Binaries\n\nThe 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).\n\u003cp\u003e\u003ca title=\"Latest version from Maven Central\" href=\"https://maven-badges.herokuapp.com/maven-central/net.zetetic/android-database-sqlcipher\"\u003e\u003cimg src=\"https://maven-badges.herokuapp.com/maven-central/net.zetetic/android-database-sqlcipher/badge.svg\"\u003e\u003c/a\u003e\u003c/p\u003e\n\n### Compatibility\n\nSQLCipher for Android runs on Android from 5.0 (API 21), for `armeabi-v7a`, `x86`, `x86_64`, and `arm64_v8a` architectures.\n\n### Contributions\n\nWe 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.\n\n### An Illustrative Terminal Listing\n\nA 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.\n\n```\n~ sjlombardo$ hexdump -C sqlite.db\n00000000 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 |SQLite format 3.|\n…\n000003c0 65 74 32 74 32 03 43 52 45 41 54 45 20 54 41 42 |et2t2.CREATE TAB|\n000003d0 4c 45 20 74 32 28 61 2c 62 29 24 01 06 17 11 11 |LE t2(a,b)$…..|\n…\n000007e0 20 74 68 65 20 73 68 6f 77 15 01 03 01 2f 01 6f | the show…./.o|\n000007f0 6e 65 20 66 6f 72 20 74 68 65 20 6d 6f 6e 65 79 |ne for the money|\n\n~ $ sqlite3 sqlcipher.db\nsqlite\u003e PRAGMA KEY=’test123′;\nsqlite\u003e CREATE TABLE t1(a,b);\nsqlite\u003e INSERT INTO t1(a,b) VALUES (‘one for the money’, ‘two for the show’);\nsqlite\u003e .quit\n\n~ $ hexdump -C sqlcipher.db\n00000000 84 d1 36 18 eb b5 82 90 c4 70 0d ee 43 cb 61 87 |.?6.?..?p.?C?a.|\n00000010 91 42 3c cd 55 24 ab c6 c4 1d c6 67 b4 e3 96 bb |.B?..?|\n00000bf0 8e 99 ee 28 23 43 ab a4 97 cd 63 42 8a 8e 7c c6 |..?(#C??.?cB..|?|\n\n~ $ sqlite3 sqlcipher.db\nsqlite\u003e SELECT * FROM t1;\nError: file is encrypted or is not a database\n```\n(example courtesy of SQLCipher)\n\n### Application Integration\n\nYou have a two main options for using SQLCipher for Android in your app:\n\n- Using it with Room or other consumers of the `androidx.sqlite` API\n\n- Using the native SQLCipher for Android classes\n\nIn both cases, you will need to add a dependency on `net.zetetic:android-database-sqlcipher`,\nsuch as having the following line in your module's `build.gradle` `dependencies`\nclosure:\n\n```gradle\nimplementation \"net.zetetic:android-database-sqlcipher:4.5.3\"\nimplementation \"androidx.sqlite:sqlite:2.1.0\"\n```\n\n(replacing `4.5.3` with the version you want)\n\n\u003ca title=\"Latest version from Maven Central\" href=\"https://maven-badges.herokuapp.com/maven-central/net.zetetic/android-database-sqlcipher\"\u003e\u003cimg src=\"https://maven-badges.herokuapp.com/maven-central/net.zetetic/android-database-sqlcipher/badge.svg\"\u003e\u003c/a\u003e\n\n#### Using SQLCipher for Android With Room\n\nSQLCipher for Android has a `SupportFactory` class in the `net.sqlcipher.database` package\nthat can be used to configure Room to use SQLCipher for Android.\n\nThere are three `SupportFactory` constructors:\n\n- `SupportFactory(byte[] passphrase)`\n- `SupportFactory(byte[] passphrase, SQLiteDatabaseHook hook)`\n- `SupportFactory(byte[] passphrase, SQLiteDatabaseHook hook, boolean clearPassphrase)`\n\nAll three take a `byte[]` to use as the passphrase (if you have a `char[]`, use\n`SQLiteDatabase.getBytes()` to get a suitable `byte[]` to use).\n\nTwo offer a `SQLiteDatabaseHook` parameter that you can use\nfor executing SQL statements before or after the passphrase is used to key\nthe database.\n\nThe three-parameter constructor also offers `clearPassphrase`, which defaults\nto `true` in the other two constructors. If `clearPassphrase` is set to `true`,\nthis will zero out the bytes of the `byte[]` after we open the database. This\nis safest from a security standpoint, but it does mean that the `SupportFactory`\ninstance is a single-use object. Attempting to reuse the `SupportFactory`\ninstance later will result in being unable to open the database, because the\npassphrase will be wrong. If you think that you might need to reuse the\n`SupportFactory` instance, pass `false` for `clearPassphrase`.\n\nThen, pass your `SupportFactory` to `openHelperFactory()` on your `RoomDatabase.Builder`:\n\n```java\nfinal byte[] passphrase = SQLiteDatabase.getBytes(userEnteredPassphrase);\nfinal SupportFactory factory = new SupportFactory(passphrase);\nfinal SomeDatabase room = Room.databaseBuilder(activity, SomeDatabase.class, DB_NAME)\n  .openHelperFactory(factory)\n  .build();\n```\n\nNow, Room will make all of its database requests using SQLCipher for Android instead\nof the framework copy of SQLCipher.\n\nNote that `SupportFactory` should work with other consumers of the `androidx.sqlite` API;\nRoom is merely a prominent example.\n\n#### Using SQLCipher for Android's Native API\n\nIf you have existing SQLite code using classes like `SQLiteDatabase` and `SQLiteOpenHelper`,\nconverting your code to use SQLCipher for Android mostly is a three-step process:\n\n1. Replace all `android.database.sqlite.*` `import` statements with ones that\nuse `net.sqlcipher.database.*` (e.g., convert `android.database.sqlite.SQLiteDatabase`\nto `net.sqlcipher.database.SQLiteDatabase`)\n\n2. Before attempting to open a database, call `SQLiteDatabase.loadLibs()`, passing\nin a `Context` (e.g., add this to `onCreate()` of your `Application` subclass, using\nthe `Application` itself as the `Context`)\n\n3. When opening a database (e.g., `SQLiteDatabase.openOrCreateDatabase()`), pass\nin the passphrase as a `char[]` or `byte[]`\n\nThe rest of your code may not need any changes.\n\nAn 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/).\n\n### ProGuard\n\nFor applications which utilize ProGuard, a few additional rules must be included when using SQLCipher for Android. These rules instruct ProGuard to omit the renaming of the internal SQLCipher classes which are used via lookup from the JNI layer. It is worth noting that since SQLCipher or Android is based on open source code there is little value in obfuscating the library anyway. The more important use of ProGuard is to protect your application code and business logic.\n\n```\n-keep,includedescriptorclasses class net.sqlcipher.** { *; }\n-keep,includedescriptorclasses interface net.sqlcipher.** { *; }\n```\n\n### Building\n\nIn order to build `android-database-sqlcipher` from source you will need both the Android SDK, Gradle, Android NDK, SQLCipher core source directory, and an OpenSSL source directory. We currently recommend using Android NDK LTS version `23.0.7599858`.\n\nTo complete the `make` command, the `ANDROID_NDK_HOME` 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:\n\n```\nSQLCIPHER_ROOT=/some/path/to/sqlcipher-folder \\\nOPENSSL_ROOT=/some/path/to/openssl-folder \\\nSQLCIPHER_CFLAGS=\"-DSQLITE_HAS_CODEC -DSQLITE_TEMP_STORE=2\" \\\nSQLCIPHER_ANDROID_VERSION=\"4.5.3\" \\\nmake build-release\n```\n\nYou may specify other build flags/features within `SQLCIPHER_CFLAGS`, however, specifying `-DSQLITE_HAS_CODEC` and `-DSQLITE_TEMP_STORE` is necessary in the list of flags.\n\n### License\n\nThe 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.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsqlcipher%2Fandroid-database-sqlcipher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsqlcipher%2Fandroid-database-sqlcipher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsqlcipher%2Fandroid-database-sqlcipher/lists"}