Git Product home page Git Product logo

dhairya0907 / react-native-encryption Goto Github PK

View Code? Open in Web Editor NEW
7.0 1.0 3.0 4.32 MB

Encryption/Decryption for React Native

Home Page: https://www.npmjs.com/package/@dhairyasharma/react-native-encryption

License: MIT License

JavaScript 1.69% Kotlin 19.52% Starlark 0.53% Ruby 1.13% Swift 65.25% Objective-C 2.17% TypeScript 9.71%
react-native encryption-decryption encryption decryption large-files file-encryption text-encryption npm-package

react-native-encryption's Introduction

@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.

react-native-encryption's People

Contributors

dhairya0907 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

react-native-encryption's Issues

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.

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.

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.

After updating react-native to version 0.72.6, I started getting an error:

FAILURE: Build failed with an exception.

* What went wrong:
The Android Gradle plugin supports only kotlin-android-extensions Gradle plugin version 1.6.20 and higher.
The following dependencies do not satisfy the required version:
project ':dhairyasharma_react-native-encryption' -> org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.30

Need to update the library?

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.

Decrypt a file in browser

I am enable to encrypt file a in mobile app but I want to decrypt the same file in web browser. Is it possible by any chance?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.