|
1 |
| -# react-native-randombytes |
| 1 | +# @react-native-oh-tpl/react-native-randombytes |
2 | 2 |
|
3 |
| -## DEPRECATED |
| 3 | +## 文档地址 / Documentation URL |
4 | 4 |
|
5 |
| -Use [react-native-get-random-values](https://www.npmjs.com/package/react-native-get-random-values) instead |
| 5 | +[中文 / Chinese](https://gitee.com/react-native-oh-library/usage-docs/blob/master/zh-cn/react-native-randombytes.md) |
6 | 6 |
|
7 |
| -## Usage |
| 7 | +## Codegen |
8 | 8 |
|
9 |
| -```js |
10 |
| -import { randomBytes } from 'react-native-randombytes' |
| 9 | +该库已接入 codegen,具体请查阅文档。 |
11 | 10 |
|
12 |
| -// synchronous API |
13 |
| -// uses SJCL |
14 |
| -const rand = randomBytes(4) |
| 11 | +## 请悉知 / Acknowledgements |
15 | 12 |
|
16 |
| -// asynchronous API |
17 |
| -// uses iOS-side SecRandomCopyBytes |
18 |
| -randomBytes(4, (err, bytes) => { |
19 |
| - // bytes is a Buffer object |
20 |
| - console.log(bytes.toString('hex')) |
21 |
| -}) |
22 |
| -``` |
23 |
| - |
24 |
| -## Installation |
25 |
| - |
26 |
| -1. Follow the steps in the next section |
27 |
| -1. You have two options depending on your needs: |
28 |
| - 1. if you're trying to get Node.js or browser crypto modules working in React Native, follow the installation workflow in [react-native-crypto](https://github.com/tradle/react-native-crypto). |
29 |
| - 1. if you only need asynchronous random bytes generation, and don't care about getting back `Buffer` objects, you can do the following: |
30 |
| - |
31 |
| - ```js |
32 |
| - import { NativeModules } from 'react-native' |
33 |
| - const { RNRandomBytes } = NativeModules |
34 |
| - RNRandomBytes.randomBytes(32, (err, bytes) => { |
35 |
| - // bytes is a base64string |
36 |
| - }) |
37 |
| - ``` |
38 |
| - |
39 |
| -### Automatic - Android / iOS (recommended) |
40 |
| - |
41 |
| -```bash |
42 |
| -react-native link |
43 |
| -``` |
44 |
| - |
45 |
| -### Manual |
46 |
| - |
47 |
| -If Automatic installation failed you, dry your tears and read on. |
48 |
| - |
49 |
| -#### `iOS` |
50 |
| - |
51 |
| -* Drag RNRandomBytes.xcodeproj from node_modules/react-native-randombytes into your XCode project. |
52 |
| - |
53 |
| -* Click on the project in XCode, go to Build Phases, then Link Binary With Libraries and add `libRNRandomBytes.a` |
54 |
| - |
55 |
| -Confused? See an example with screenshots [here](http://facebook.github.io/react-native/docs/linking-libraries-ios.html#content) |
56 |
| - |
57 |
| - |
58 |
| -#### `Android` |
59 |
| - |
60 |
| -* Update Gradle Settings |
61 |
| - |
62 |
| -```gradle |
63 |
| -// file: android/settings.gradle |
64 |
| -... |
65 |
| -
|
66 |
| -include ':randombytes', ':app' |
67 |
| -project(':randombytes').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-randombytes/android') |
68 |
| -``` |
69 |
| - |
70 |
| -* Update Gradle Build |
71 |
| - |
72 |
| -```gradle |
73 |
| -// file: android/app/build.gradle |
74 |
| -... |
75 |
| -
|
76 |
| -dependencies { |
77 |
| - ... |
78 |
| - compile project(':randombytes') |
79 |
| -} |
80 |
| -``` |
81 |
| - |
82 |
| -* Register React Package |
83 |
| - |
84 |
| -```java |
85 |
| -... |
86 |
| -import com.bitgo.randombytes.RandomBytesPackage // import |
87 |
| -
|
88 |
| -public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler { |
89 |
| -
|
90 |
| - private ReactInstanceManager mReactInstanceManager; |
91 |
| - private ReactRootView mReactRootView; |
92 |
| -
|
93 |
| - @Override |
94 |
| - protected void onCreate(Bundle savedInstanceState) { |
95 |
| - super.onCreate(savedInstanceState); |
96 |
| - mReactRootView = new ReactRootView(this); |
97 |
| - mReactInstanceManager = ReactInstanceManager.builder() |
98 |
| - .setApplication(getApplication()) |
99 |
| - .setBundleAssetName("index.android.bundle") |
100 |
| - .setJSMainModuleName("index.android") |
101 |
| - .addPackage(new MainReactPackage()) |
102 |
| - .addPackage(new RandomBytesPackage()) // register package here |
103 |
| - .setUseDeveloperSupport(BuildConfig.DEBUG) |
104 |
| - .setInitialLifecycleState(LifecycleState.RESUMED) |
105 |
| - .build(); |
106 |
| - mReactRootView.startReactApplication(mReactInstanceManager, "AwesomeProject", null); |
107 |
| - setContentView(mReactRootView); |
108 |
| - } |
109 |
| -... |
110 |
| -
|
111 |
| -``` |
112 |
| - |
113 |
| -### `Windows` |
114 |
| - |
115 |
| - |
116 |
| -```bash |
117 |
| -react-native link react-native-randombytes |
118 |
| -``` |
119 |
| - |
120 |
| -Depending on your project versions and the state of RN-Windows this may not always work. If it does not, a manual installation guide can be found here: |
121 |
| - |
122 |
| -https://github.com/Microsoft/react-native-windows/blob/master/docs/LinkingLibrariesWindows.md |
| 13 | +本项目基于 [The MIT License (MIT)](https://github.com/react-native-oh-library/react-native-randombytes/blob/sig/LICENSE) ,请自由地享受和参与开源。 |
123 | 14 |
|
0 commit comments