Native SHA256/SHA1 Hashing for React Native

1.4.10 · active · verified Sun Apr 19

react-native-sha256 provides performant, native SHA256 and SHA1 hashing capabilities for strings and byte arrays within React Native applications. Leveraging native modules on both iOS and Android, it significantly outperforms JavaScript-only implementations in terms of speed, which is crucial for mobile performance. The current stable version is 1.4.10, with releases occurring sporadically based on maintenance and feature additions. Key differentiators include its native execution, support for both SHA256 and SHA1 (since version 1.3.6), and built-in TypeScript definitions, making it suitable for modern React Native development. While it supports traditional `react-native link` for older projects, it also outlines CocoaPods integration for iOS, aligning with contemporary React Native setups. For file hashing, it suggests integration with `react-native-fs` rather than providing its own implementation.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to compute SHA256 hashes for both string and byte array inputs.

import { sha256 } from 'react-native-sha256';

// Hash a simple string
sha256("Hello, checklist.day!").then(hash => {
    console.log('SHA256 Hash:', hash);
}).catch(error => {
    console.error('Hashing error:', error);
});

// For hashing byte arrays, prepare the array
const messageBytes = new Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100]); // 'Hello World'
import { sha256Bytes } from 'react-native-sha256';
sha256Bytes(Array.from(messageBytes)).then(hash => {
    console.log('SHA256 Bytes Hash:', hash);
}).catch(error => {
    console.error('Hashing bytes error:', error);
});

view raw JSON →