You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+60-8Lines changed: 60 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -44,20 +44,72 @@ Error: file is encrypted or is not a database
44
44
45
45
### Application Integration
46
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:
47
+
You have a two main options for using SQLCipher for Android in your app:
48
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:
49
+
- Using it with Room or other consumers of the `androidx.sqlite` API
52
50
51
+
- Using the native SQLCipher for Android classes
52
+
53
+
In both cases, you will need to add a dependency on `net.zetetic:android-database-sqlcipher`,
54
+
such as having the following line in your module's `build.gradle``dependencies`
Now, Room will make all of its database requests using SQLCipher for Android instead
90
+
of the framework copy of SQLCipher.
91
+
92
+
Note that `SupportFactory` should work with other consumers of the `androidx.sqlite` API;
93
+
Room is merely a prominent example.
94
+
95
+
#### Using SQLCipher for Android's Native API
96
+
97
+
If you have existing SQLite code using classes like `SQLiteDatabase` and `SQLiteOpenHelper`,
98
+
converting your code to use SQLCipher for Android mostly is a three-step process:
99
+
100
+
1. Replace all `android.database.sqlite.*``import` statements with ones that
101
+
use `net.sqlcipher.database.*` (e.g., convert `android.database.sqlite.SQLiteDatabase`
102
+
to `net.sqlcipher.database.SQLiteDatabase`)
103
+
104
+
2. Before attempting to open a database, call `SQLiteDatabase.loadLibs()`, passing
105
+
in a `Context` (e.g., add this to `onCreate()` of your `Application` subclass, using
106
+
the `Application` itself as the `Context`)
107
+
108
+
3. When opening a database (e.g., `SQLiteDatabase.openOrCreateDatabase()`), pass
109
+
in the passphrase as a `char[]` or `byte[]`
110
+
111
+
The rest of your code may not need any changes.
112
+
61
113
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/).
0 commit comments