Blazing fast ⚡⚡⚡ Secure Hash Algorithm solution for React Native with direct C++ bindings

Overview

React Native SHA library

React-native-sha is a blazing fast solution for performing Secure Hashing Algorithm in React Native. Main reason this library is incredibly fast is because it provides bindings to a C++ implementation of the hashing algorithm through the Javascript Interface (JSI).

⚠️ ⚠️ ⚠️ This library currently has support for android only. IOS developers (mainly ObjC) needed to add support for IOS.

Features

  • Support for SHA-1, SHA-256, SHA3-224, SHA3-256, SHA3-384, SHA3-512
  • Direct bindings to C++ library, hence
  • Synchronous function calls
  • 160x faster than current popular solutions
  • Supports compounded hashing of byte chunks
SHA256 sha256 = new SHA256();
while(data is available) {
  sha256.add(chunk, chunk size)
}

sha256.gethash(); //sha-256 of entire data

Benchmarks

alt text

alt text

alt text

alt text

alt text

alt text

Installation

Installing react-native-sha with npm

  npm install react-native-sha

JSI is still in an experimental stage and hence a little workaround is required to link the library to your project. The facebook team is working on a feature, Turbo modules which will autolink your JSI modules in the future.

import com.facebook.react.bridge.JSIModulePackage;
import com.reactnativesha.ShaJsiPackage;


public class MainApplication extends Application implements ReactApplication {

  private final ReactNativeHost mReactNativeHost =
      new ReactNativeHost(this) {

        ///....

        @Override
        protected String getJSMainModuleName() {
          return "index";
        }


        // Add this method to your MainApplication

        @Override
        protected JSIModulePackage getJSIModulePackage() {
          return new ShaJsiPackage();
        }
      };

API Reference

All classes implement the Hash interface.

interface HashInterface {
  getHash: () => string;
  add: (buf: ArrayBuffer, bufSize: number) => void;
  reset: () => void;
  computeHash: (text: string) => string;
}
Function Parameters Description
getHash() none Returns the latest hash as string
add() buf: ArrayBuffer bufSize: number adds abitrary number of bytes as ArrayBuffer. Support for more byte formats coming soon
reset() none flushes added bytes out of memory
computeHash() text: string Accepts a string and returns its hash as a string

Examples

import { SHA256 } from 'react-native-sha';
import { Buffer } from 'buffer'; //needs to be installed in RN environment
import { data } from './test.json';

const sha256 = new SHA256();
sha256.computeHash('hash the world'); //33e9b48e6afb96bc6195f02102831b37c9cebbdacf9173df1881b9a7764444ae

const dataToProcess = Buffer.from(data, 'base64').buffer; //ArrayBuffer
sha256.add(dataToProcess, dataToProcess.byteLength);
sha256.getHash(); // hash of data

sha256.reset(); //flushes hash out of memory

SHA-3 with different variants

const sha3_256 = new SHA3('256');
sha3_256.computeHash('hash the world'); //623734226db189364e8a996cf05936b1b42cd8cfc9247040fd61d571

// same api as rest of the classes

Credits

Contributing

Contributions are always welcome!

See contributing.md for ways to get started.

License

MIT

You might also like...
haha - huh? another hashing algorithm

haha - huh? another hashing algorithm 📙 haha is a hashing algorithm I've written as an exercise and as something to use for myself. It's decently fas

A C++ implementation of the graph algorithm of finding all strongly connected components with DFS

SinkSCC A C++ implementation of the graph algorithm of finding all strongly connected components with DFS. Details Each SCC of a graph can be treated

The Implementation of quadtree-based multi-thread tiled pyramid building algorithm.

tile-map-parallel-builder Quadtree-based multi-thread tiled pyramid building algorithm. Core Concept NOTE: The level is different from TMS zoom level.

C implementation of a sudoku solver with backtracking algorithm
C implementation of a sudoku solver with backtracking algorithm

SUDOKU SOLVER Sudoku solver using backtracking algorithm Sudoku game To solve a sudoku, you need a sudoku. So i made a basic implmentation of one with

Pottery - A container and algorithm template library in C

Pottery - A container and algorithm template library in C

I implement what i learned about banker's algorithm in OS course at my uni.
I implement what i learned about banker's algorithm in OS course at my uni.

Banker-s-Algorithm The banker’s algorithm is a resource allocation and deadlock avoidance algorithm that tests for safety by simulating the allocation

This program uses genetic algorithm to find the best route possible given the conditions.
This program uses genetic algorithm to find the best route possible given the conditions.

Genetic Algorithm Table Of Contents Table Of Contents Installation About Terms The Algorithm Default values for the conditions Example result Installa

Implementation of Dijkstra's algorithm for finding the shortest paths between nodes in a graph using Priority Queue data structure in C

Implementation of Dijkstra's algorithm for finding the shortest paths between nodes in a graph using Priority Queue data structure in C. File "airport

 An algorithm to compute the coefficients of a function development in a spherical harmonics convergent series
An algorithm to compute the coefficients of a function development in a spherical harmonics convergent series

An algorithm to compute the coefficients of a function development in a spherical harmonics convergent series

Releases(v0.1.6)
  • v0.1.6(Nov 26, 2021)

    • removed react-native field in package.json causing dependency resolving issue 581fe68

    https://github.com/henrhie/react-native-sha/compare/v0.1.5...v0.1.6

    Source code(tar.gz)
    Source code(zip)
  • v0.1.5(Nov 25, 2021)

  • v0.1.4(Nov 25, 2021)

  • v0.1.3(Nov 25, 2021)

    • added files not to be included in package in files filed in package.json 7a9f686

    https://github.com/henrhie/react-native-sha/compare/v0.1.2...v0.1.3

    Source code(tar.gz)
    Source code(zip)
  • v0.1.2(Nov 25, 2021)

  • v0.1.1(Nov 24, 2021)

    • added test scripts 6bf8e39
    • Merge https://github.com/henrhie/react-native-sha 568c7a0
    • remove test scripts 0f355f0
    • Update README.md 992011d
    • Update README.md bf62372
    • Update README.md 8db9c9a
    • Update README.md 4bbdfe6
    • added doc images 787ac2e

    https://github.com/henrhie/react-native-sha/compare/535c14499388d338f1c421634ad8ac218cdd1f19...v0.1.1

    Source code(tar.gz)
    Source code(zip)
Knapsack Encryption Algorithm is the first general public key cryptography algorithm.

Knapsack Encryption Algorithm is the first general public key cryptography algorithm. It is developed by Ralph Merkle and Mertin Hellman in 1978. As it is a Public key cryptography, it needs two different keys. One is Public key which is used for Encryption process and the other one is Private key which is used for Decryption process.

Farhan Izzaturrahman Andiejanto 1 Nov 10, 2021
My attempt at implementing the fast voxel traversal algorithm by Amanatides and Woo using OpenGL

Attempt at implementing the fast voxel traversal algorithm Works on both Linux and Windows. Recommended software: Linux: Visual Studio Code / Windows:

Niklas Mäckle 2 Sep 24, 2021
CComp: A Parallel Compression Algorithm for Compressed Word Search

The goal of CComp is to achieve better compressed search times while achieving the same compression-decompression speed as other parallel compression algorithms. CComp achieves this by splitting both the word dictionaries and the input stream, processing them in parallel.

Emir Öztürk 4 Sep 30, 2021
C Program showing line drawing using DDA algorithm.

Draw-Line-Using-DDA-algorithm C Program showing line drawing using DDA algorithm. How it works ? ??

CodAffection 2 Sep 28, 2021
Quick sort is a highly efficient sorting algorithm and is based on partitioning of array of data into smaller arrays.

Quick sort is a highly efficient sorting algorithm and is based on partitioning of array of data into smaller arrays. A large array is partitioned into two arrays one of which holds values smaller than the specified value, say pivot, based on which the partition is made and another array holds values greater than the pivot value.

Lakshan Sandanayaka 2 Sep 21, 2021
This project implemented the Mean Value Coordinates in 3D algorithm in c++

Mean Value Coordinates in 3D [c++] | Paper link on Sciencedirect | Pdf version link | This project implemented the Mean Value Coordinates in 3D algori

null 2 Nov 18, 2021
Based on the spatial resection theory, the algorithm solves the camera position by solving the homography matrix.

Based on the spatial resection theory, the algorithm solves the camera position by solving the homography matrix.

null 1 Nov 13, 2021
Final Project for Multicore Processors Course at NYU: Parallel Ray Tracing Algorithm

Multicore_ParallelRayTracing Final Project for Multicore Processors Course at NYU: Parallel Ray Tracing Algorithm Team Member: Hanlin He, Yaowei Zong,

Hanlin || Herlin 1 Dec 1, 2021
C++ and SFML Project that simulates dijkstra algorithm on a non oriented Graph

Dijkstra-Simulator Table of Contents About The Project Built With Getting Started Prerequisites Roadmap Acknowledgments About The Project This is one

David 2 Mar 26, 2022
Basic algorithm developed in C++

Sequential Search Algorithm O(n) Algoritmo Comportamento Funcional Se o valor que deseja pesquisar dentro do array de fato existir, então a função ret

Guilherme Serafim Kollet 1 Oct 24, 2021