npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@dhairyasharma/react-native-encryption

v1.0.0

Published

Encryption/Decryption for React Native

Downloads

152

Readme

@dhairyasharma/react-native-encryption

Supports Android, iOS MIT License Maintenance Maintainer Generic badge

Twitter LinkedIn

Encryption/decryption for React Native.

 

Benchmark

| |
| :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | File Details | | File Linkhttp://bit.do/benchmarkfileFile Size1.09 GB | | IOS Benchmark | | Average of 100 Encryption4.859 secondsAverage of 100 Decryption5.594 secondsCheck Log for all IOS encryption here.Check Log for all IOS decryption here. | | Android Benchmark | | Average of 100 Encryption20.373 secondsAverage of 100 Decryption21.908 secondsCheck 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.