Generate cryptographically-secure random bytes in react native
npm install react-native-awesome-secure-randomA library to generate cryptographically-secure random bytes. Uses SecRandomCopyBytes on iOS, SecureRandom on Android and System.Security.Cryptography.RandomNumberGenerator on Windows.
Promise that resolves with a Uint8Array.``javascript
import { generateSecureRandom } from 'react-native-securerandom';
generateSecureRandom(12).then(randomBytes => console.log(randomBytes));
`
$ yarn add react-native-securerandom
$ react-native link react-native-securerandom
#### iOS
##### With Cocoapods
1. Add pod 'RNSecureRandom', :path => '../node_modules/react-native-securerandom' to your Podfile (changing your node_modules path as appropriate)pod install
2. Run from the same directory as your Podfile
##### Without Cocoapods
1. In XCode, in the project navigator, right click Libraries ➜ Add Files to [your project's name]node_modules
2. Go to ➜ react-native-securerandom and add RNSecureRandom.xcodeprojlibRNSecureRandom.a
3. In XCode, in the project navigator, select your project. Add to your project's Build Phases ➜ Link Binary With Libraries
#### Android
1. Open up android/app/src/main/java/[...]/MainActivity.javaimport net.rhogan.rnsecurerandom.RNSecureRandomPackage;
- Add to the imports at the top of the filenew RNSecureRandomPackage()
- Add to the list returned by the getPackages() methodandroid/settings.gradle
2. Append the following lines to :`
`
include ':react-native-securerandom'
project(':react-native-securerandom').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-securerandom/android')
android/app/build.gradle
3. Insert the following lines inside the dependencies block in :`
`
compile project(':react-native-securerandom')
#### Windows
1. In Visual Studio add node_modules/react-native-securerandom/windows/RNSecureRandom.sln folder to your solution, and reference from your app.MainPage.cs
2. Open up your app's using Net.Rhogan.RNSecureRandom.RNSecureRandom;
- Add to the usings at the top of the filenew RNSecureRandomPackage()
- Add to the List returned by the Packages` method