# react-native-simple-crypto

> A simpler React-Native crypto library

Latest version **0.3.0** (published 2026-02-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-native-simple-crypto
pnpm add react-native-simple-crypto
yarn add react-native-simple-crypto
bun add react-native-simple-crypto
```

## Health

**Score 55/100 (C)** — status: stable.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2026-02-21 |
| First published | 2019-01-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 167 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 40 |
| Author | Gary Button |
| Maintainers | ghbutton |
| Keywords | react-native, react-component, ios, android, aes, crypto, mobile, async, sha1, sha256, sha512, pbkdf2, hmac256, rsa, random, randomBytes |

## Links

- npm: https://www.npmjs.com/package/react-native-simple-crypto
- Repository: https://github.com/ghbutton/react-native-simple-crypto
- Issues: https://github.com/ghbutton/react-native-simple-crypto/issues
- npm.io page: https://npm.io/package/react-native-simple-crypto

## Dependencies (1)

- [base64-js](https://npm.io/package/base64-js.md) ^1.5.1

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.3.0 (latest) — 2026-02-21
- 0.2.15 — 2020-10-08
- 0.2.14 — 2020-09-02
- 0.2.13 — 2020-07-22
- 0.2.12 — 2020-05-17
- 0.2.11 — 2020-05-15
- 0.2.9 — 2020-04-27
- 0.2.8 — 2019-08-02
- 0.2.7 — 2019-05-27
- 0.2.6 — 2019-01-26
- 0.2.5 — 2019-01-10
- 0.2.4 — 2019-01-10
- 0.2.3 — 2019-01-10
- 0.2.2 — 2019-01-10
- 0.2.1 — 2019-01-10
- … 7 more at https://npm.io/package/react-native-simple-crypto/versions

## README

# React Native Simple Crypto [![npm version](https://badge.fury.io/js/react-native-simple-crypto.svg)](https://badge.fury.io/js/react-native-simple-crypto)

A simpler React-Native crypto library

## Features

- AES-128-CBC
- HMAC-SHA256
- SHA1
- SHA256
- SHA512
- PBKDF2
- RSA

## Installation

```bash
npm install react-native-simple-crypto
```

For React Native 0.60+, autolinking handles native setup automatically. For iOS, run `cd ios && pod install`.

## API

All methods are asynchronous and return promises (except for convert utils)

```typescript
- AES
  - encrypt(text: ArrayBuffer, key: ArrayBuffer, iv: ArrayBuffer)
  - decrypt(cipherText: ArrayBuffer, key: ArrayBuffer, iv: ArrayBuffer)
- SHA
  - sha1(text: string)
  - sha1(text: ArrayBuffer)
  - sha256(text: string)
  - sha256(text: ArrayBuffer)
  - sha512(text: string)
  - sha512(text: ArrayBuffer)
- HMAC
  - hmac256(text: ArrayBuffer, key: ArrayBuffer)
- PBKDF2
  - hash(password: string, salt: ArrayBuffer, iterations: number, keyLength: number, hash: string)
- RSA
  - generateKeys(keySize: number)
  - sign(data: string, key: string, hash: string)
  - verify(data: string, secretToVerify: string, hash: string)
  - encrypt(data: string, key: string) (Expects UTF8 string data inputs)
  - decrypt(data: string, key: string) (Returns UTF8 string)
  - encrypt64(data: string, key: string) (Expects Base64 string data inputs)
  - decrypt64(data: string, key: string) (Returns Base64 string)
- utils
  - randomBytes(bytes: number)
  - convertArrayBufferToUtf8(input: ArrayBuffer)
  - convertUtf8ToArrayBuffer(input: string)
  - convertArrayBufferToBase64(input: ArrayBuffer)
  - convertBase64ToArrayBuffer(input: string)
  - convertArrayBufferToHex(input: ArrayBuffer)
  - convertHexToArrayBuffer(input: string)
```

> _NOTE:_ Supported hashing algorithms for RSA and PBKDF2 are:
>
> `"Raw" (RSA-only) | "SHA1" | "SHA224" | "SHA256" | "SHA384" | "SHA512"`

## Example

```javascript
import RNSimpleCrypto from "react-native-simple-crypto";

// -- AES ------------------------------------------------------------- //
const message = "data to encrypt";
const messageBuffer = RNSimpleCrypto.utils.convertUtf8ToArrayBuffer(message);
const key = await RNSimpleCrypto.utils.randomBytes(16);
const iv = await RNSimpleCrypto.utils.randomBytes(16);

const cipherText = await RNSimpleCrypto.AES.encrypt(messageBuffer, key, iv);
const decrypted = await RNSimpleCrypto.AES.decrypt(cipherText, key, iv);
console.log(RNSimpleCrypto.utils.convertArrayBufferToUtf8(decrypted)); // "data to encrypt"

// -- SHA ------------------------------------------------------------- //
const sha256 = await RNSimpleCrypto.SHA.sha256("test");

// -- HMAC ------------------------------------------------------------ //
const hmacKey = await RNSimpleCrypto.utils.randomBytes(32);
const signature = await RNSimpleCrypto.HMAC.hmac256(messageBuffer, hmacKey);

// -- PBKDF2 ---------------------------------------------------------- //
const derivedKey = await RNSimpleCrypto.PBKDF2.hash("password", "salt", 4096, 32, "SHA1");

// -- RSA ------------------------------------------------------------- //
const rsaKeys = await RNSimpleCrypto.RSA.generateKeys(2048);
const encrypted = await RNSimpleCrypto.RSA.encrypt(message, rsaKeys.public);
const decryptedRsa = await RNSimpleCrypto.RSA.decrypt(encrypted, rsaKeys.private);

const sig = await RNSimpleCrypto.RSA.sign(message, rsaKeys.private, "SHA256");
const valid = await RNSimpleCrypto.RSA.verify(sig, message, rsaKeys.public, "SHA256");
```

## Running E2E Tests

The test suite uses a React Native example app with [Maestro](https://maestro.mobile.dev/) for E2E testing. Tests cover AES, SHA, HMAC, PBKDF2, RSA, and utility functions (22+ assertions).

### Prerequisites

- Xcode with iOS Simulator
- [Maestro CLI](https://maestro.mobile.dev/getting-started/installing-maestro)

```bash
curl -Ls "https://get.maestro.mobile.dev" | bash
```

### Setup

```bash
# Install library dependencies (needed for base64-js)
npm install

# Install example app dependencies
cd example
npm install
cd ios && bundle exec pod install && cd ..
```

### Run

```bash
# Terminal 1: Start Metro
cd example
npx react-native start --reset-cache

# Terminal 2: Build and run the app on simulator
cd example
npx react-native run-ios --simulator="iPhone 16 Pro"

# Terminal 3: Run Maestro tests (once the app is loaded)
maestro test maestro/flows/run_all_tests.yaml
```

You can also run individual test modules:

```bash
maestro test maestro/flows/aes_tests.yaml
maestro test maestro/flows/sha_tests.yaml
maestro test maestro/flows/hmac_tests.yaml
maestro test maestro/flows/pbkdf2_tests.yaml
maestro test maestro/flows/rsa_tests.yaml
maestro test maestro/flows/utils_tests.yaml
```

## Forked Libraries

- [@trackforce/react-native-crypto](https://github.com/trackforce/react-native-crypto)
- [react-native-randombytes](https://github.com/mvayngrib/react-native-randombytes)

---
_Source: https://npm.io/package/react-native-simple-crypto · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
