Registry / auth-security / react-native-sha256

react-native-sha256

JSON →
library1.4.10jsnpmunverified

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.

npm install react-native-sha256
INSTALL
IMPORT
SIG · REACT-NATIVE-SHA25
R
react-native-sha256
auth-securityjavascriptv1.4.10
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

sha256
import { sha256 } from 'react-native-sha256';
const { sha256 } = require('react-native-sha256');
Primarily designed for ESM and TypeScript; CommonJS `require` might lead to issues or type inference problems.
sha256Bytes
import { sha256Bytes } from 'react-native-sha256';
Used for hashing byte arrays (Uint8Array converted to Array<number>).
sha1
import { sha1 } from 'react-native-sha256';
import sha1 from 'react-native-sha256';
SHA-1 support was added in version 1.3.6 and is a named export.

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); });
Debug
Known issues
breakingFor React Native versions 0.60 and above, `react-native link` is deprecated in favor of auto-linking. Manual linking or specific CocoaPods configurations might be necessary.
fix
For React Native >=0.60, remove `react-native link`. Ensure `pod install` is run in your `ios/` directory. If auto-linking fails, follow manual linking steps for iOS/Android modules as per React Native documentation.
affects: >=1.0.0
gotchaThis library provides native modules and requires proper native project setup (CocoaPods for iOS, Gradle for Android). Forgetting `pod install` or `react-native link` (for older RN versions) will result in runtime errors.
fix
After adding the package, run `cd ios && pod install` for iOS projects. For older RN versions, run `react-native link react-native-sha256`. Always clear caches (`npm start --reset-cache`) and rebuild native projects.
affects: >=1.0.0
gotchaThe `sha256Bytes` method expects an `Array<number>`, not a `Uint8Array` directly. You must convert `Uint8Array` instances using `Array.from()`.
fix
If you have a `Uint8Array`, convert it to a regular JavaScript array: `sha256Bytes(Array.from(yourUint8Array))`.
affects: >=1.0.0
deprecatedWhile SHA-1 is supported, it is cryptographically broken and should not be used for security-critical applications like password hashing or digital signatures. Use SHA-256 instead.
fix
Prefer `sha256` over `sha1` for all new implementations where collision resistance is important.
affects: >=1.3.6
Errors
Common errors & fixes
Invariant Violation: Native module RNSha256 not found. Did you link all the native dependencies and rebuild your app?
The native module for react-native-sha256 was not correctly linked or built into your application.
fix
For React Native <0.60: Run `react-native link react-native-sha256`. For React Native >=0.60: Ensure auto-linking is working; navigate to `ios/` and run `pod install`. For Android, ensure Gradle builds correctly. Clean your build caches and rebuild the native project.
ld: framework not found RNSha256 for architecture x86_64
iOS linker error indicating the RNSha256 framework (or library) is missing from the Xcode build.
fix
Run `cd ios && pod install` to ensure CocoaPods integrates the library. If using manual linking, verify the `.xcodeproj` file is added to your Libraries in Xcode and the target's 'Build Phases' link binary with libraries includes `libRNSha256.a`.
TypeError: null is not an object (evaluating 'RNSha256.sha256')
The JavaScript bridge to the native module is `null`, meaning the native module could not be loaded or initialized at runtime.
fix
This typically points to the same underlying linking issues as 'Native module RNSha256 not found'. Verify installation steps, clear Metro cache (`npm start --reset-cache`), and perform a clean native build (`cd ios && rm -rf build && pod install && cd .. && npx react-native run-ios` for iOS).
Upgrade
Version history
1.4.10latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
8
OpenAI (training)
1
Resources
react-native-sha256 — npm install react-native-sha256 · libregistry