1- # Datastore encryption
1+ # DocumentStore encryption
22
3- Android’s datastore now supports encryption of all data inside your database
3+ Android’s document store now supports encryption of all data inside your database
44using 256-bit AES: JSON documents, Query indexes and attachments.
55
66JSON documents and Query indexes are stored in SQLite databases. We use
@@ -43,7 +43,7 @@ Once you've included the binaries in your app's build, you need to perform some
4343 SQLiteDatabase.loadLibs(this);
4444 ```
4545
46- 2. With encryption, two parameters are required in the ` openDatastore ` call: the
46+ 2. With encryption, two parameters are required in the ` getInstance ` call: the
4747 application storage path and a ` KeyProvider ` object. The ` KeyProvider ` interface
4848 can be instantiated with the ` SimpleKeyProvider ` class, which just provides a
4949 developer or user set encryption key. Create a new SimpleKeyProvider
@@ -57,10 +57,9 @@ Once you've included the binaries in your app's build, you need to perform some
5757 byte[ ] key = "testAKeyPasswordtestAKeyPassword".getBytes();
5858 KeyProvider keyProvider = new SimpleKeyProvider(key);
5959
60- File path = getApplicationContext().getDir("datastores", MODE_PRIVATE);
61- DatastoreManager manager = DatastoreManager.getInstance(path.getAbsolutePath());
60+ File path = getApplicationContext().getDir("documentstores", MODE_PRIVATE);
6261
63- Datastore ds = manager.openDatastore("my_datastore" , keyProvider);
62+ DocumentStore ds = DocumentStore.getInstance(new File(path, "my_documentstore") , keyProvider);
6463 ```
6564
6665 Note: The key _must_ be 32 bytes (256-bit key). `"testAKeyPasswordtestAKeyPassword"`
@@ -84,7 +83,7 @@ Example:
8483``` java
8584KeyProvider keyProvider = new AndroidKeyProvider (context,
8685 " ASecretPassword" , " AnIdentifier" );
87- Datastore ds = manager . openDatastore( " my_datastore " , keyProvider);
86+ DocumentStore ds = DocumentStore . getInstance( new File (path, " my_documentstore " ) , keyProvider);
8887```
8988
9089One example of an identifier might be if multiple users share the same
@@ -106,18 +105,16 @@ protected void onCreate(Bundle savedInstanceState) {
106105
107106 SQLiteDatabase . loadLibs(this );
108107
109- // Create a DatastoreManager with encryption using
108+ // Get a DocumentStore instance with encryption using
110109 // application internal storage path and a key
111- File path = getApplicationContext(). getDir(" datastores " , MODE_PRIVATE );
110+ File path = getApplicationContext(). getDir(" documentstores " , MODE_PRIVATE );
112111 KeyProvider keyProvider =
113112 new SimpleKeyProvider (" testAKeyPasswordtestAKeyPassword" . getBytes());
114113
115- DatastoreManager manager = DatastoreManager . getInstance(path. getAbsolutePath());
116-
117- Datastore ds = null ;
114+ DocumentStore ds = null ;
118115 try {
119- ds = manager . openDatastore( " my_datastore " , keyProvider);
120- } catch (DatastoreNotCreatedException e) {
116+ ds = DocumentStore . getInstance( new File (path, " my_documentstore " ) , keyProvider);
117+ } catch (DocumentStoreNotOpenedException e) {
121118 e. printStackTrace();
122119 }
123120
@@ -168,7 +165,7 @@ saving to disk. There should be no licencing concerns for using JCE.
168165Databases are automatically encrypted with
169166[SQLCipher][SQLCipher]. SQLCipher requires including its
170167[BSD-style license][BSD-style license] and copyright in your application and
171- documentation. Therefore, if you use datastore encryption in your application,
168+ documentation. Therefore, if you use document store encryption in your application,
172169please follow the instructions mentioned [here](https://www.zetetic.net/sqlcipher/open-source/).
173170
174171[SQLCipher]: https://www.zetetic.net/sqlcipher/
0 commit comments