Skip to content

Commit eec1d9c

Browse files
Merge pull request #29 from yoman07/master
Added possibility to set ACCESSIBLE level for iOS
2 parents eac08e5 + b23e00a commit eec1d9c

File tree

9 files changed

+2485
-883
lines changed

9 files changed

+2485
-883
lines changed

README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ $ react-native link react-native-secure-key-store
4848
## Usage
4949

5050
```javascript
51-
import RNSecureKeyStore from 'react-native-secure-key-store';
51+
import RNSecureKeyStore, {ACCESSIBLE} from "react-native-secure-key-store";
5252

5353
// For storing key
54-
RNSecureKeyStore.set("key1", "value1")
54+
RNSecureKeyStore.set("key1", "value1", {accessible: ACCESSIBLE.ALWAYS_THIS_DEVICE_ONLY})
5555
.then((res) => {
5656
console.log(res);
5757
}, (err) => {
@@ -76,6 +76,24 @@ RNSecureKeyStore.remove("key1")
7676
```
7777
- For demo app, checkout example directory.
7878

79+
## Options
80+
81+
| Key | Platform | Description | Default |
82+
|---|---|---|---|
83+
|**`accessible`**|iOS only|This dictates when a keychain item is accessible, see possible values in `Keychain.ACCESSIBLE`. |*`Keychain.ACCESSIBLE.WHEN_UNLOCKED`*|
84+
85+
### `Keychain.ACCESSIBLE` enum
86+
87+
| Key | Description |
88+
|-----|-------------|
89+
|**`WHEN_UNLOCKED`**|The data in the keychain item can be accessed only while the device is unlocked by the user.|
90+
|**`AFTER_FIRST_UNLOCK`**|The data in the keychain item cannot be accessed after a restart until the device has been unlocked once by the user.|
91+
|**`ALWAYS`**|The data in the keychain item can always be accessed regardless of whether the device is locked.|
92+
|**`WHEN_PASSCODE_SET_THIS_DEVICE_ONLY`**|The data in the keychain can only be accessed when the device is unlocked. Only available if a passcode is set on the device. Items with this attribute never migrate to a new device.|
93+
|**`WHEN_UNLOCKED_THIS_DEVICE_ONLY`**|The data in the keychain item can be accessed only while the device is unlocked by the user. Items with this attribute do not migrate to a new device.|
94+
|**`AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY`**|The data in the keychain item cannot be accessed after a restart until the device has been unlocked once by the user. Items with this attribute never migrate to a new device.|
95+
|**`ALWAYS_THIS_DEVICE_ONLY`**|The data in the keychain item can always be accessed regardless of whether the device is locked. Items with this attribute never migrate to a new device.|
96+
7997
## Testing
8098

8199
For Testing using Jest, add RNSecureKeyStoreMock implementation under your __test__/__mocks__ folder.

android/src/main/java/com/reactlibrary/securekeystore/RNSecureKeyStoreModule.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import java.security.PrivateKey;
2828
import java.security.PublicKey;
2929
import java.util.Calendar;
30+
import android.support.annotation.Nullable;
31+
import com.facebook.react.bridge.ReadableMap;
3032

3133
import javax.crypto.Cipher;
3234
import javax.crypto.CipherInputStream;
@@ -51,7 +53,7 @@ public String getName() {
5153
}
5254

5355
@ReactMethod
54-
public void set(String alias, String input, Promise promise) {
56+
public void set(String alias, String input, @Nullable ReadableMap options, Promise promise) {
5557
try {
5658
setCipherText(alias, input);
5759
promise.resolve("stored ciphertext in app storage");

example/app/app.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ import {
1212
View
1313
} from 'react-native';
1414

15-
import RNSecureKeyStore from "react-native-secure-key-store";
15+
import RNSecureKeyStore, {ACCESSIBLE} from "react-native-secure-key-store";
1616

1717
export default class example extends Component {
1818
render() {
1919

20-
RNSecureKeyStore.set("key1", "value1")
20+
RNSecureKeyStore.set("key1", "value1", {accessible: ACCESSIBLE.ALWAYS_THIS_DEVICE_ONLY})
2121
.then((res) => {
2222
console.log(res);
2323
}, (err) => {
2424
console.log(err);
2525
});
2626

27-
RNSecureKeyStore.set("key2", "value2")
27+
RNSecureKeyStore.set("key2", "value2", {accessible: ACCESSIBLE.ALWAYS_THIS_DEVICE_ONLY})
2828
.then((res) => {
2929
console.log(res);
3030
}, (err) => {

0 commit comments

Comments
 (0)