React Native Quick Crypto
Introduction

Complete Setup Process

Detailed guide for installation and configuration

This guide covers the full installation process, including how to configure RNQC as a drop-in replacement for the Node.js crypto module.

Installation

Install the package and the required react-native-nitro-modules core.

Install Dependencies

bun add react-native-quick-crypto react-native-nitro-modules

Install Pods (iOS)

Navigate to the iOS directory and install CocoaPods.

cd ios && pod install

For Expo projects, use the Expo CLI to ensure compatibility.

Install Dependencies

npx expo install react-native-quick-crypto

Add Config Plugin

Add the library to your plugins list in app.json (or app.config.js).

app.json
{
  "expo": {
    "plugins": [
      "react-native-quick-crypto"
    ]
  }
}

Prebuild

Generate the native android and ios directories.

npx expo prebuild

This library requires native code. You must run prebuild to generate the native directories. It will not work in Expo Go.

If you want crypto and Buffer to be available globally (as they are in Node.js), import the install function as early as possible in your application's entry point (e.g., index.js).

import { install } from 'react-native-quick-crypto';

install();

Configuration

Use metro.config.js to redirect imports at the bundler level. This is generally more robust.

Open Config

Open your metro.config.js file.

Add Resolver

Add the resolveRequest handler to redirect crypto imports.

metro.config.js
const { getDefaultConfig } = require('@react-native/metro-config');

const config = getDefaultConfig(__dirname);

config.resolver.resolveRequest = (context, moduleName, platform) => {
  if (moduleName === 'crypto') {
    // when importing crypto, resolve to react-native-quick-crypto
    return context.resolveRequest(
      context,
      'react-native-quick-crypto',
      platform,
    );
  }
  
  // otherwise chain to the standard Metro resolver.
  return context.resolveRequest(context, moduleName, platform);
};

module.exports = config;

Alternatively, use babel-plugin-module-resolver to alias imports during transpilation.

Install Plugin

yarn add --dev babel-plugin-module-resolver

Update Babel Config

Add the plugin to your babel.config.js.

babel.config.js
module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  plugins: [
+   [
+     'module-resolver',
+     {
+       alias: {
+         'crypto': 'react-native-quick-crypto',
+         'stream': 'readable-stream',
+         'buffer': '@craftzdog/react-native-buffer',
+       },
+     },
+   ],
    ...
  ],
};

Reset Cache

Restart your bundler to apply changes.

yarn start --reset-cache

XSalsa20 Support (Optional)

If you need to use the xsalsa20 cipher algorithm, you must enable libsodium support by setting an environment variable before building your native code:

export SODIUM_ENABLED=1

This can be done:

  • iOS: Export the variable export SODIUM_ENABLED=1 before running pod install.
  • Android: Add sodiumEnabled=true to your project's gradle.properties file.

Without this flag, attempting to use xsalsa20 will throw a runtime error: "libsodium must be enabled to use this cipher"

On this page