mirror of
https://github.com/status-im/react-native-securerandom.git
synced 2026-08-27 17:11:14 +00:00
0.1.0
react-native-random-bytes
A library to generate cryptographically-secure random bytes. Uses SecRandomCopyBytes on iOS and SecureRandom on Android.
Usage
The library exports a single function:
generateRandomBytes(length: number) => Promise<Uint8Array>
Takes a length, the number of bytes to generate, and returns a Promise that resolves with a Uint8Array.
import { generateRandomBytes } from 'react-native-random-bytes';
generateRandomBytes(12).then(randomBytes => console.log(randomBytes));
Installation
$ yarn add react-native-random-bytes
Automatic linking with react-native link
$ react-native link react-native-random-bytes
Manual linking
iOS
- In XCode, in the project navigator, right click
Libraries➜Add Files to [your project's name] - Go to
node_modules➜react-native-random-bytesand addRNRandomBytes.xcodeproj - In XCode, in the project navigator, select your project. Add
libRNRandomBytes.ato your project'sBuild Phases➜Link Binary With Libraries - Run your project (
Cmd+R)<
Android
- Open up
android/app/src/main/java/[...]/MainActivity.java
- Add
import net.rhogan.rnrandombytes.RNRandomBytesPackage;to the imports at the top of the file - Add
new RNRandomBytesPackage()to the list returned by thegetPackages()method
- Append the following lines to
android/settings.gradle:include ':react-native-random-bytes' project(':react-native-random-bytes').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-random-bytes/android') - Insert the following lines inside the dependencies block in
android/app/build.gradle:compile project(':react-native-random-bytes')
Languages
C#
31.3%
C++
28.6%
Java
16%
Objective-C
9%
JavaScript
6%
Other
9.1%