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
**react-native-sensitive-info** is the next generation of [react-native-get-shared-prefs](https://www.npmjs.com/package/react-native-get-shared-prefs).
7
9
8
10
# Introduction
9
11
10
-
`react-native-sensitive-info` manages all data stored in Android Shared Preferences and iOS Keychain. You can set and get all key/value using simple methods.
12
+
`react-native-sensitive-info` manages all data stored in Android Shared Preferences, iOS Keychain and Windows Credentials. You can set and get all key/value using simple methods.
11
13
12
14
13
15
| RN SensitiveInfo Version | Description |
@@ -19,7 +21,7 @@
19
21
20
22
Install `react-native-sensitive-info` using:
21
23
22
-
``npm i -S react-native-sensitive-info``
24
+
``npm i -S react-native-sensitive-info`` or ``yarn add react-native-sensitive-info``
* Open the solution in Visual Studio for your Windows apps.
82
95
83
-
We introduced **Android Keystore** security into our library. Also, we've fixed some issues and updated example.
96
+
* Right click your in the Explorer and click Add > Existing Project....
84
97
85
-
Thanks to all contributors who helped us on our journey :)
98
+
* Navigate to ./<app-name>/node_modules/react-native-sensitive-info/windows/RNSensitiveInfo/RNSensitiveInfo/ and add RNSensitiveInfo.csproj.
86
99
87
-
## Since version >= 3.0.0
100
+
* Right click on your React Native Windows app under your solutions directory and click Add > Reference....
101
+
102
+
* Check the RNSensitiveInfo you just added and press Ok
103
+
104
+
* Open MainPage.cs in your app
105
+
106
+
```
107
+
using RNSqlite2;
108
+
109
+
get
110
+
{
111
+
return new List<IReactPackage>
112
+
{
113
+
new MainReactPackage(),
114
+
new RNSensitiveInfoPackage(),
115
+
};
116
+
}
117
+
```
118
+
119
+
120
+
### Expo
121
+
122
+
As noted by by [@Palisand](https://github.com/Palisand) in [this issue](https://github.com/mCodex/react-native-sensitive-info/issues/50#issuecomment-334583668), it's not possible to use this module with Expo, unless your project is detached. The same is true for any modules with native code, it's not an issue with `react-native-sensitive-info`. You may want to try [SecureStore](https://docs.expo.io/versions/latest/sdk/securestore.html) from Expo itself.
123
+
124
+
# Methods
88
125
89
126
We unified our library's methods to bring more efficiency and simplify the usability for other developers. We hope that you enjoy it. :)
90
127
91
-
`setItem(key, value, options)`: You can insert data into shared preferences & keychain using this method.
128
+
`isHardwareDetected()`: resolves to a boolean that indicates the detection of fingerprint hardware
129
+
130
+
`hasEnrolledFingerprints()`: resolves to a boolean that indicates the enrollment status of fingerprints on the device
131
+
132
+
`isSensorAvailable`: resolves to a boolean that indicates the overall availability of fingerprint sensor (a combination of the previous two methods)
133
+
134
+
`setItem(key, value, options)`: You can insert data into shared preferences & keychain using this promise method.
92
135
93
136
`getItem(key, options)`: This promise will get value from given key.
94
137
95
-
`deleteItem(key, options)`: (New method since this version) It will delete value from given key
138
+
`deleteItem(key, options)`: It will delete value from given key
96
139
97
140
`getAllItems(options)`: Will retrieve all keys and values from Shared Preferences & Keychain
But if you prefer to not use it, our default sharedPreferencesName is: **shared_preferences** and keychainService is: **app**
151
+
If you used Android's getDefaultSharedPreferences in your project the shared preference's name that you are looking for is: **com.mypackage.MyApp_preferences**. On the other hand if you used iOS's Keychain the default service is: **app** which is our default too.
152
+
153
+
### Android Specific Options
109
154
110
-
If you used Android's getDefaultSharedPreferences in your project the shared preference's name that you are looking for is: **com.mypackage.MyApp_preferences**. In other hands if you used iOS's Keychain the default service is: **app** which is our default too.
155
+
#### showModal & strings
156
+
157
+
When passing in `touchID` and `showModal` (Android only) options as `true`, an Android native prompt will show up asking for user's authentication. This behavior is similar to that of iOS.
158
+
159
+
You can control strings associated with a modal prompt via `strings` option:
160
+
```javascript
161
+
strings: {
162
+
header:'Sign in',
163
+
description:'Place finger to authenticate',
164
+
hint:'Touch',
165
+
success:'Fingerprint recognized',
166
+
notRecognized:'Fingerprint not recognized, try again',
167
+
cancel:'Cancel',
168
+
cancelled:'Authentication was cancelled', // reject error message
169
+
}
170
+
```
171
+
172
+
### iOS Specific Options
173
+
174
+
#### kSecAccessControl
175
+
176
+
When passing in the `touchID` option as `true`, you can also set `kSecAccessControl`. For example:
Note: By default `kSecAccessControl` will get set to `kSecAccessControlUserPresence`.
111
188
112
189
# How to use?
113
190
@@ -118,29 +195,45 @@ import SInfo from 'react-native-sensitive-info';
118
195
119
196
SInfo.setItem('key1', 'value1', {
120
197
sharedPreferencesName:'mySharedPrefs',
121
-
keychainService:'myKeychain',
122
-
encrypt:true
123
-
});
198
+
keychainService:'myKeychain'
199
+
}).then((value) =>
200
+
console.log(value) //value 1
201
+
);
124
202
125
-
SInfo.setItem('key2', 'value2');
203
+
SInfo.setItem('key2', 'value2', {});
126
204
127
205
SInfo.getItem('key1', {
128
206
sharedPreferencesName:'mySharedPrefs',
129
207
keychainService:'myKeychain'}).then(value=> {
130
208
console.log(value) //value1
131
209
});
132
210
133
-
SInfo.getItem('key2').then(value=> {
211
+
SInfo.getItem('key2',{}).then(value=> {
134
212
console.log(value) //value2
135
213
});
136
214
137
215
SInfo.getAllItems({
138
216
sharedPreferencesName:'mySharedPrefs',
139
217
keychainService:'myKeychain'}).then(values=> {
140
-
console.log(values) //value1
218
+
console.log(values) //value1, value2
141
219
});
142
220
```
143
221
222
+
# Protect your item with fingerprint
223
+
As jailbroken device can access your iOS Keychain/ Android shared preference and key store in plain text, it is necessary to add another layer of protection so even jailbreaking won't leak your data (like refresh_token or bank account password).
224
+
- for iOS it is implemented though [Access Control](https://developer.apple.com/documentation/security/secaccesscontrol). Everytime when app wants to access the protected keychain item, a prompt by iOS will show up. Only when authentication success will the app get the keychain item.
225
+
- for Android it is implemented though [FingerprintManager](https://developer.android.com/reference/android/hardware/fingerprint/FingerprintManager.html) + Keystore. Keystore has a function called `setUserAuthenticationRequired` which makes Keystore requires user authentication before getting value. However Android doesn't nicely user to scan their finger, it just throws error. Here is where FingerprintManager comes in. However (AGAIN) FingerprintManager doesn't show prompt for you, so you need to build UI yourself to let user to know that it is time to scan fingerprint.
226
+
227
+
**The example in the repo shows how to use this feature and how to build some Android UI based on callbacks.**
228
+
229
+
**NOTE: fingerprint will only work with Android 6.0 and above.**
230
+
231
+
HELP NEEDED: It will be nice if someone can build an Android native prompt to make Android touch as easy to use as iOS. Maybe we can borrow some code from [google's example](https://github.com/googlesamples/android-FingerprintDialog)
232
+
233
+
# Use with redux-persist
234
+
235
+
If you would like to use [redux-persist](https://github.com/rt2zz/redux-persist) to store information from your Redux state into secure storage, you can use [redux-persist-sensitive-storage](https://github.com/CodingZeal/redux-persist-sensitive-storage), which provides a custom storage back-end for redux-persist that uses react-native-sensitive-info.
0 commit comments