{"id":11799,"library":"react-native-sha256","title":"Native SHA256/SHA1 Hashing for React Native","description":"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.","status":"active","version":"1.4.10","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/itinance/react-native-sha256","tags":["javascript","react-component","react-native","ios","android","hash","sha256","sha1","SHA","typescript"],"install":[{"cmd":"npm install react-native-sha256","lang":"bash","label":"npm"},{"cmd":"yarn add react-native-sha256","lang":"bash","label":"yarn"},{"cmd":"pnpm add react-native-sha256","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Primarily designed for ESM and TypeScript; CommonJS `require` might lead to issues or type inference problems.","wrong":"const { sha256 } = require('react-native-sha256');","symbol":"sha256","correct":"import { sha256 } from 'react-native-sha256';"},{"note":"Used for hashing byte arrays (Uint8Array converted to Array<number>).","symbol":"sha256Bytes","correct":"import { sha256Bytes } from 'react-native-sha256';"},{"note":"SHA-1 support was added in version 1.3.6 and is a named export.","wrong":"import sha1 from 'react-native-sha256';","symbol":"sha1","correct":"import { sha1 } from 'react-native-sha256';"}],"quickstart":{"code":"import { sha256 } from 'react-native-sha256';\n\n// Hash a simple string\nsha256(\"Hello, checklist.day!\").then(hash => {\n    console.log('SHA256 Hash:', hash);\n}).catch(error => {\n    console.error('Hashing error:', error);\n});\n\n// For hashing byte arrays, prepare the array\nconst messageBytes = new Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100]); // 'Hello World'\nimport { sha256Bytes } from 'react-native-sha256';\nsha256Bytes(Array.from(messageBytes)).then(hash => {\n    console.log('SHA256 Bytes Hash:', hash);\n}).catch(error => {\n    console.error('Hashing bytes error:', error);\n});","lang":"typescript","description":"Demonstrates how to compute SHA256 hashes for both string and byte array inputs."},"warnings":[{"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.","message":"For 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.","severity":"breaking","affected_versions":">=1.0.0"},{"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.","message":"This 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"If you have a `Uint8Array`, convert it to a regular JavaScript array: `sha256Bytes(Array.from(yourUint8Array))`.","message":"The `sha256Bytes` method expects an `Array<number>`, not a `Uint8Array` directly. You must convert `Uint8Array` instances using `Array.from()`.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Prefer `sha256` over `sha1` for all new implementations where collision resistance is important.","message":"While 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.","severity":"deprecated","affected_versions":">=1.3.6"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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.","cause":"The native module for react-native-sha256 was not correctly linked or built into your application.","error":"Invariant Violation: Native module RNSha256 not found. Did you link all the native dependencies and rebuild your app?"},{"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`.","cause":"iOS linker error indicating the RNSha256 framework (or library) is missing from the Xcode build.","error":"ld: framework not found RNSha256 for architecture x86_64"},{"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).","cause":"The JavaScript bridge to the native module is `null`, meaning the native module could not be loaded or initialized at runtime.","error":"TypeError: null is not an object (evaluating 'RNSha256.sha256')"}],"ecosystem":"npm"}