Encryption/Decryption for React Native

Overview

@dhairyasharma/react-native-encryption

Supports Android, iOS MIT License Maintenance Maintainer Generic badge

Twitter LinkedIn

Encryption/decryption for React Native.

 

Benchmark

File Details
File Link
http://bit.do/benchmarkfile
File Size
1.09 GB
IOS Benchmark
Average of 100 Encryption
4.859 seconds

Average of 100 Decryption
5.594 seconds

Check Log for all IOS encryption here.
Check Log for all IOS decryption here.
Android Benchmark
Average of 100 Encryption
20.373 seconds

Average of 100 Decryption
21.908 seconds

Check Log for all Android encryption here.
Check Log for all Android decryption here.

 

Features

  • Encrypt/decrypt any length of text.
  • Encrypt/decrypt any type of file.
  • Encrypt/decrypt any size of file.

 

Getting started

Install the library using either Yarn:

yarn add @dhairyasharma/react-native-encryption

or npm:

npm install --save @dhairyasharma/react-native-encryption

or git:

npm install git+https://github.com/dhairya0907/react-native-encryption.git

Using React Native >= 0.60

  Linking the package manually is not required anymore with Autolinking.

  • iOS Platform:
cd ios && pod install && cd ..
  • Android Platform:

    Does not require any additional steps.

Usage

Import the library

import RNEncryptionModule from "@dhairyasharma/react-native-encryption";

Encrypt Text

RNEncryptionModule.encryptText(
    plainText,
    password
    ).then((res: any) => {
        if (res.status == "success") {
            console.log("success", res)
        } else {
            Alert.alert("Error", res);
        }
        }).catch((err: any) => {
            console.log(err);
        });
  • plainText : Plain text to be encrypted.
  • password : Password to encrypt the plain text.
returns

// If text encryption is successful, it returns a JSON object with the following structure:
{
  "status": "success",
  "encryptedText": "encryptedText",
  "iv": "iv",
  "salt": "salt"
}

or

// If text encryption is unsuccessful, it returns a JSON object with the following structure:
{
  "status": "Fail",
  "error": "error"
}

Decrypt Text

RNEncryptionModule.decryptText(
    encryptedText,
    password,
    iv,
    salt).then((res: any) => {
        if (res.status == "success") {
            console.log("success", res)
        } else {
            Alert.alert("Error", res);
        }
        }).catch((err: any) => {
            console.log(err);
        });
  • encryptedText : Cipher text to be decrypted.
  • password : Password to decrypt the cipher text.
  • iv : Initialization vector from encryptText.
  • salt : Salt from encryptText.
returns

// If text decryption is successful, it returns a JSON object with the following structure:
{
  "status": "success",
  "decryptedText": "decryptedText"
}

or

// If text decryption is unsuccessful, it returns a JSON object with the following structure:
{
  "status": "Fail",
  "error": "error"
}

Encrypt File

 RNEncryptionModule.encryptFile(
      inputFilePath,
      outputEncryptedFilePath,
      password
    ).then((res: any) => {
        if (res.status == "success") {
            console.log("success", res)
        } else {
            console.log("error", res);
        }
        }).catch((err: any) => {
            console.log(err);
        });
  • inputFilePath : Path of the file to be encrypted.
  • outputEncryptedFilePath : Path of the encrypted file.
  • password : Password to encrypt the file.
returns

// If file encryption is successful, it returns a JSON object with the following structure:
{
  "status": "success",
  "iv": "iv",
  "salt": "salt"

}

or

// If file encryption is unsuccessful, it returns a JSON object with the following structure:
{
  "status": "Fail",
  "error": "error"
}

Decrypt File

 RNEncryptionModule.decryptFile(
      encryptedFilePath,
      outputDecryptedFilePath,
      password,
      iv,
      salt
    ).then((res: any) => {
        if (res.status == "success") {
            console.log("success", res)
        } else {
            console.log("error", res);
        }
        }).catch((err: any) => {
            console.log(err);
        });
  • encryptedFilePath : Path of the file to be decrypted.
  • outputDecryptedFilePath : Path of the decrypted file.
  • password : Password to decrypt the file.
  • iv : Initialization vector from encryptFile.
  • salt : Salt from encryptFile.
returns

// If file decryption is successful, it returns a JSON object with the following structure:
{
  "status": "success",
  "message" : "File decrypted successfully"

}

or

// If file decryption is unsuccessful, it returns a JSON object with the following structure:
{
  "status": "Fail",
  "error": "error"
}

NOTE

On android, Input or Output file path does not support content://  type file path. Please use file://  type file path.

You can use react-native-fetch-blob stat to get original path. See example.

You will need Files and media permission for this.


 

Acknowledgements

 

Author

Dhairya Sharma | @dhairya0907

 

License

The library is released under the MIT license. For more information see LICENSE.

You might also like...
iOS's Stocks App clone written in React Native for demo purpose (available both iOS and Android).
iOS's Stocks App clone written in React Native for demo purpose (available both iOS and Android).

FinanceReactNative iOS's Stocks App clone written in React Native for demo purpose (available both iOS and Android). Data is pulled from Yahoo Finance

React Native Photo Editor (RNPE)
React Native Photo Editor (RNPE)

React Native Photo Editor (RNPE) 🌄 Image editor using native modules for iOS an

Discover Movies and TV shows -  React Native
Discover Movies and TV shows - React Native

movieapp Discover Movies and TV shows Download APK file Download from Google Drive - v2.2.1 What's included Name Description React Native Build Native

All my React Native examples

ReactNativeExamples All my React Native examples and experiements can be found here. This repo is divided into two sub folders, Instructions git clone

React Native Twitch application
React Native Twitch application

Notes I'm going to rewrite this project 😉 . Be ready to new Twitch application. Twitch This project was built for The Rolling Scopes #18 meetup. As o

React Native Todo List example app which uses Redux for managing app state
React Native Todo List example app which uses Redux for managing app state

react-native-redux-todo-list A sample todo list app developed by using React Native and Redux. How to run the app Install react-native If you don't ha

A simple To Do application written in React Native

Example To Do List application in react-native Requirements, install as needed: React Native: $ npm i -g react-native-cli watchman: $ brew install wa

A property finder application written using React Native

React Native PropertyFinder App This repository accompanies the tutorial I published on Ray Wenderlich's website, which describes the process of build

🏀 iOS and Android NBA app created with React Native
🏀 iOS and Android NBA app created with React Native

Swish An iOS and Android NBA app created with React Native. If you would like to request a feature, find a bug, have a question, or would like to leav

Comments
  • why returning iv and salt after file encryption

    why returning iv and salt after file encryption

    I'm doing an app that encrypts and decrypts files. The problem is the returned iv and salt are needed for decryption and in that case I have to store those both iv and salt with the key. Why not let us pass the iv and salt ourselves to the encryption? Those two parameters we can generate and pass them to the encrypt function, we just need to store only the key ourselves.

    opened by ngdph 2
  • Is there a way to detect if the key is wrong ?

    Is there a way to detect if the key is wrong ?

    Hello,

    First of all, thank you very much for this awesome package. I'm using it to encrypt files, but I noticed that even when the key is wrong it returns "success". Is there a way to know if the entered key is wrong ?

    Thank you in advance.

    Best regards.

    opened by lucienbl 2
  • files are not decrypt after encrypt.

    files are not decrypt after encrypt.

    Describe the bug A clear and concise description of what the bug is.

    To Reproduce Steps to reproduce the behavior:

    1. Go to '...'
    2. Click on '....'
    3. Scroll down to '....'
    4. See error

    Expected behavior A clear and concise description of what you expected to happen.

    Screenshots If applicable, add screenshots to help explain your problem.

    Desktop (please complete the following information):

    • OS: [e.g. iOS]
    • Browser [e.g. chrome, safari]
    • Version [e.g. 22]

    Smartphone (please complete the following information):

    • Device: [e.g. iPhone6]
    • OS: [e.g. iOS8.1]
    • Browser [e.g. stock browser, safari]
    • Version [e.g. 22]

    Additional context Add any other context about the problem here.

    opened by Ameer-Hamza-Developer 2
  • TypeError: Cannot read property 'encryptFile' of null

    TypeError: Cannot read property 'encryptFile' of null

    Describe the bug Hi, I ran into a problem like the title, I logged the RNEncryptionModule and the result was null.

    To Reproduce Import import RNEncryptionModule from '@dhairyasharma/react-native-encryption';

    Use it await RNEncryptionModule.encryptFile(file.fileCopyUri, outputPath, hexKey); The file.fileCopyUri, outputPath and hexKey are all strings represent input file path, output file path and the key to encrypt.

    Expected behavior The file is encrypted.

    Screenshots image

    I'm using React Native 0.70.3.

    opened by ngdph 1
Releases(v1.0.0)
Vahesaroyan-react-native-bubble-select - React native bubble picker

@vahesaroyan/react-native-bubble-select React native bubble picker Installation

Vahe Saroyan 0 Jan 30, 2022
React Native library that implements PayPal Checkout flow using purely native code (swift).

react-native-paypal-swift React Native library that implements PayPal Checkout flow using purely native code (swift). Installation npm install react-n

Tibb 6 Nov 28, 2022
A react native interface for integrating payments using Braintree

A react native interface for integrating payments using Braintree

eKreative 17 Dec 30, 2022
React Native 实现无侵入自定义下拉刷新组件

react-native-ly-refresh-control 下拉刷新 iOS 基于MJRefresh 通过RCTCustomRefreshContolProtocol实现RefreshControl组件封装 JS端可以无侵入自定义下拉刷新只需要替换对应的refreshControl Androi

少言 12 Jul 2, 2022
iOS 15 share play API in react-native

react-native-shareplay iOS 15 share play API in react-native Installation yarn add react-native-shareplay And go to Xcode Capabilities and enable "Gro

Popshop Live 27 Oct 16, 2022
React Native package for interacting with HomeKit devices

React Native package for interacting with HomeKit devices

Ibrahim Berat Kaya 4 Dec 24, 2021
react native esptouch

react-native-esptouch One should know that This is a Unofficial project. The official demo is below: EsptouchForAndroid EsptouchForIOS Getting started

五毛共和国 Wumaoland 0 Oct 25, 2021
React Native Template for Taro

React Native Template for Taro requirement taro: @tarojs/cli@^3.2.0 framework: 'react' quick start install react native library install peerDependenci

null 1 Nov 20, 2021
A suite of IoT tools to use with React Native.

react-native-iot-tools WIP. A suite of IoT tools for React Native applications. Package iOS Android @react-native-iot-tools/bluetooth ✅ ❌ @react-nativ

Sara Pope 3 Oct 31, 2022
A testing MQTT react native library

react-native-awesome-testing abc Installation npm install react-native-awesome-testing Usage import { multiply } from "react-native-awesome-testing";

null 0 Nov 26, 2021