Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
expo-random
Advanced tools
The expo-random package is a utility for generating cryptographically secure random numbers. It is particularly useful in scenarios where security and unpredictability are crucial, such as in generating tokens, keys, or other secure identifiers.
Generating Random Bytes
This feature allows you to generate a specified number of random bytes asynchronously. The example code generates 16 random bytes and logs them to the console.
const { getRandomBytesAsync } = require('expo-random');
(async () => {
const randomBytes = await getRandomBytesAsync(16);
console.log(randomBytes);
})();
Generating Random Bytes Synchronously
This feature allows you to generate a specified number of random bytes synchronously. The example code generates 16 random bytes and logs them to the console.
const { getRandomBytes } = require('expo-random');
const randomBytes = getRandomBytes(16);
console.log(randomBytes);
The 'crypto' module is a built-in Node.js module that provides cryptographic functionality, including a method for generating random bytes. It is similar to expo-random in that it can generate cryptographically secure random numbers, but it is more versatile and widely used in Node.js applications.
The 'randombytes' package is a simple wrapper around the Node.js 'crypto' module's randomBytes function. It provides a similar functionality to expo-random, allowing for the generation of cryptographically secure random bytes. It is often used in environments where the full 'crypto' module is not available.
This package is now deprecated in favor of expo-crypto
, which provides the same functionality.
To migrate, replace all imports from expo-random
with imports from expo-crypto
.
Provides a native interface for creating strong random bytes. With Random
you can generate random values to address use cases that other APIs like the web's crypto.getRandomValues
and Node's crypto.randomBytes
might address.
For managed Expo projects, please follow the installation instructions in the API documentation for the latest stable release.
You can add a polyfill for the web's crypto.getRandomValues
by installing expo-standard-web-crypto and importing it in SDK 39 and higher:
import { polyfillWebCrypto } from 'expo-standard-web-crypto';
polyfillWebCrypto();
// crypto.getRandomValues is now globally defined
Other libraries like react-native-get-random-values may work too.
For bare React Native projects, you must ensure that you have installed and configured the expo
package before continuing.
npx expo install expo-random
Run npx pod-install
after installing the npm package.
No additional set up necessary.
FAQs
Expo universal module for random bytes
The npm package expo-random receives a total of 147,180 weekly downloads. As such, expo-random popularity was classified as popular.
We found that expo-random demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 27 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.