<p align="center"><img src="https://user-images.githubusercontent.com/378279/36642269-6195b10c-1a3d-11e8-9e1b-37a3d1bcf7b3.png" align="center" width="150" height="201" alt="" /></p>
<h1 align="center">react-native-keychain</h1>
[![Travis](https://img.shields.io/travis/oblador/react-native-keychain.svg)](https://travis-ci.org/oblador/react-native-keychain) [![npm](https://img.shields.io/npm/v/react-native-keychain.svg)](https://npmjs.com/package/react-native-keychain) [![npm](https://img.shields.io/npm/dm/react-native-keychain.svg)](https://npmjs.com/package/react-native-keychain)
Keychain/Keystore Access for React Native.
## Installation
1. `$ yarn add react-native-keychain`
2. `$ react-native link react-native-keychain` and check `MainApplication.java` to verify the package was added.
3. Rebuild your project with `react-native run-ios/android`
See manual installation below if you have issues with `react-native link`.
## Usage
```js
import * as Keychain from 'react-native-keychain';
async () => {
const username = 'zuck';
const password = 'poniesRgr8';
// Store the credentials
await Keychain.setGenericPassword(username, password);
try {
// Retreive the credentials
const credentials = await Keychain.getGenericPassword();
if (credentials) {
console.log('Credentials successfully loaded for user ' + credentials.username);
} else {
console.log('No credentials stored')
}
} catch (error) {
console.log('Keychain couldn\'t be accessed!', error);
}
await Keychain.resetGenericPassword()
}
```
See `KeychainExample` for fully working project example.
Both `setGenericPassword` and `setInternetCredentials` are limited to strings only, so if you need to store objects etc, please use `JSON.stringify`/`JSON.parse` when you store/access it.
### `setGenericPassword(username, password, [{ accessControl, accessible, accessGroup, service }])`
Will store the username/password combination in the secure storage. Resolves to `true` or rejects in case of an error.
### `getGenericPassword([{ authenticationPrompt, service }])`
Will retreive the username/password combination from the secure storage. Resolves to `{ username, password }` if an entry exists or `false` if it doesn't. It will reject only if an unexpected error is encountered like lacking entitlements or permission.
### `resetGenericPassword([{ service }])`
Will remove the username/password combination from the secure storage.
### `setInternetCredentials(server, username, password, [{ accessControl, accessible, accessGroup }])`
Will store the server/username/password combination in the secure storage.
### `getInternetCredentials(server, [{ authenticationPrompt }])`
Will retreive the server/username/password combination from the secure storage. Resolves to `{ username, password }` if an entry exists or `false` if it doesn't. It will reject only if an unexpected error is encountered like lacking entitlements or permission.
### `resetInternetCredentials(server)`
Will remove the server/username/password combination from the secure storage.
### `requestSharedWebCredentials()` (iOS only)
Asks the user for a shared web credential. Requires additional setup both in the app and server side, see [Apple documentation](https://developer.apple.com/documentation/security/shared_web_credentials). Resolves to `{ server, username, password }` if approved and `false` if denied and throws an error if not supported on platform or there's no shared credentials.
### `setSharedWebCredentials(server, username, password)` (iOS only)
Sets a shared web credential. Resolves to `true` when successful.
### `canImplyAuthentication([{ authenticationType }])`
Inquire if the type of local authentication policy is supported on this device with the device settings the user chose. Should be used in combination with `accessControl` option in the setter functions. Resolves to `true` if supported.
### `getSupportedBiometryType()`
Get what type of hardware biometry support the device has. Resolves to a `Keychain.BIOMETRY_TYPE` value when supported, otherwise `null`.
### Options
| Key | Platform | Description | Default |
|---|---|---|---|
|**`accessControl`**|iOS only|This dictates how a keychain item may be used, see possible values in `Keychain.ACCESS_CONTROL`. |*None*|
|**`accessible`**|iOS only|This dictates when a keychain item is accessible, see possible values in `Keychain.ACCESSIBLE`. |*`Keychain.ACCESSIBLE.WHEN_UNLOCKED`*|
|**`accessGroup`**|iOS only|In which App Group to share the keychain. Requires additional setup with entitlements. |*None*|
|**`authenticationPrompt`**|iOS only|What to prompt the user when unlocking the keychain with biometry or device password. |`Authenticate to retrieve secret`|
|**`authenticationType`**|iOS only|Policies specifying which forms of authentication are acceptable. |`Keychain.AUTHENTICATION_TYPE.DEVICE_PASSCODE_OR_BIOMETRICS`|
|**`service`**|All|Reverse domain name qualifier for the service associated with password. |*App bundle ID*|
#### `Keychain.ACCESS_CONTROL` enum
| Key | Description |
|-----|-------------|
|**`USER_PRESENCE`**|Constraint to access an item with either Touch ID or passcode.|
|**`BIOMETRY_ANY`**|Constraint to access an item with Touch ID for any enrolled fingers.|
|**`BIOMETRY_CURRENT_SET`**|Constraint to access an item with Touch ID for currently enrolled fingers.|
|**`DEVICE_PASSCODE`**|Constraint to access an item with a passcode.|
|**`APPLICATION_PASSWORD`**|Constraint to use an application-provided password for data encryption key generation.|
|**`BIOMETRY_ANY_OR_DEVICE_PASSCODE`**|Constraint to access an item with Touch ID for any enrolled fingers or passcode.|
|**`BIOMETRY_CURRENT_SET_OR_DEVICE_PASSCODE`**|Constraint to access an item with Touch ID for currently enrolled fingers or passcode.|
#### `Keychain.ACCESSIBLE` enum
| Key | Description |
|-----|-------------|
|**`WHEN_UNLOCKED`**|The data in the keychain item can be accessed only while the device is unlocked by the user.|
|**`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.|
|**`ALWAYS`**|The data in the keychain item can always be accessed regardless of whether the device is locked.|
|**`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.|
|**`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.|
|**`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.|
|**`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.|
#### `Keychain.AUTHENTICATION_TYPE` enum
| Key | Description |
|-----|-------------|
|**`DEVICE_PASSCODE_OR_BIOMETRICS`**|Device owner is going to be authenticated by biometry or device passcode.|
|**`BIOMETRICS`**|Device owner is going to be authenticated using a biometric method (Touch ID or Face ID).|
#### `Keychain.BIOMETRY_TYPE` enum
| Key | Description |
|-----|-------------|
|**`TOUCH_ID`**|Device supports authentication with Touch ID.|
|**`FACE_ID`**|Device supports authentication with Face ID.|
|**`FINGERPRINT`**|Device supports authentication with Android Fingerprint.|
## Manual Installation
### iOS
#### Option: Manually
* Right click on Libraries, select **Add files to "…"** and select `node_modules/react-native-keychain/RNKeychain.xcodeproj`
* Select your project and under **Build Phases** -> **Link Binary With Libraries**, press the + and select
没有合适的资源?快使用搜索试试~ 我知道了~
react-native-keychain-master.zip_React_handd55_keychain_react-na
共79个文件
java:12个
json:5个
js:4个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 61 浏览量
2022-09-24
23:03:18
上传
评论
收藏 239KB ZIP 举报
温馨提示
react-native-keychain Keychain/Keystore Access for React Native.
资源详情
资源评论
资源推荐
收起资源包目录
react-native-keychain-master.zip (79个子文件)
react-native-keychain-master
.travis.yml 1010B
index.js 7KB
RNKeychain.xcodeproj
project.pbxproj 14KB
android
gradlew.bat 2KB
gradlew 5KB
gradle
wrapper
gradle-wrapper.jar 52KB
gradle-wrapper.properties 230B
src
main
java
com
oblador
keychain
KeychainPackage.java 981B
exceptions
EmptyParameterException.java 184B
CryptoFailedException.java 280B
KeyStoreAccessException.java 200B
cipherStorage
CipherStorageFacebookConceal.java 4KB
CipherStorage.java 1KB
CipherStorageKeystoreAESCBC.java 8KB
KeychainModule.java 9KB
PrefsStorage.java 4KB
DeviceAvailability.java 929B
AndroidManifest.xml 190B
build.gradle 529B
.flowconfig 1KB
package.json 879B
.prettierrc 73B
RNKeychainManager
RNKeychainManager.h 285B
RNKeychainManager.m 17KB
LICENSE 1KB
.npmignore 82B
.gitignore 682B
typings
react-native-keychain.d.ts 3KB
RNKeychain.podspec 672B
README.md 12KB
yarn.lock 236B
KeychainExample
ios
KeychainExampleTests
KeychainExampleTests.m 2KB
Info.plist 765B
KeychainExample.xcodeproj
project.pbxproj 60KB
xcshareddata
xcschemes
KeychainExample-tvOS.xcscheme 5KB
KeychainExample.xcscheme 5KB
KeychainExample-tvOSTests
Info.plist 765B
KeychainExample-tvOS
Info.plist 2KB
KeychainExample
main.m 510B
AppDelegate.h 451B
AppDelegate.m 1KB
Base.lproj
LaunchScreen.xib 4KB
Images.xcassets
AppIcon.appiconset
Contents.json 585B
Contents.json 63B
Info.plist 2KB
.babelrc 34B
index.js 131B
.watchmanconfig 2B
android
gradlew.bat 2KB
gradlew 5KB
gradle.properties 887B
keystores
debug.keystore.properties 105B
BUCK 152B
app
proguard-rules.pro 3KB
src
main
res
mipmap-hdpi
ic_launcher.png 3KB
values
strings.xml 78B
styles.xml 192B
mipmap-xxhdpi
ic_launcher.png 8KB
mipmap-mdpi
ic_launcher.png 2KB
mipmap-xhdpi
ic_launcher.png 5KB
java
com
keychainexample
MainActivity.java 375B
MainApplication.java 1KB
AndroidManifest.xml 1KB
BUCK 2KB
build.gradle 6KB
gradle
wrapper
gradle-wrapper.jar 51KB
gradle-wrapper.properties 203B
settings.gradle 215B
build.gradle 642B
.flowconfig 1KB
package.json 505B
__tests__
App.js 267B
app.json 67B
.gitignore 763B
App.js 6KB
.buckconfig 114B
yarn.lock 175KB
.gitattributes 16B
.editorconfig 214B
共 79 条
- 1
御道御小黑
- 粉丝: 58
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0