Skip to content
This repository has been archived by the owner on Apr 13, 2022. It is now read-only.

A hardware-backed encryption and decryption library for React Native

License

Notifications You must be signed in to change notification settings

paritytech/React-Native-ECEncryption

Repository files navigation

React-Native-EC-Encryption

npm version License: GPL v3

Description

This library is used for simple hardware-backed ECIES encryption and decryption on both iOS and Android.

iOS

On iOS it use Secure Enclave for store the private key, and save public key to keychain. For getting the private key for decryption, user will need to enter his TouchID or FaceID if any is set.

Algorithm used: ECIESEncryptionStandardX963SHA256AESGCM

Android

On Android it use google Tink for an easy application logic. It currently does not bound with Biometric Auth, but I will follow the discussion here

Algorithm used: ECIES_P256_HKDF_HMAC_SHA256_AES128_CTR_HMAC_SHA256

Getting started

The library should be automatically linked on installation.

$ npm install react-native-ec-encryption --save

For iOS:

An extra installation step is needed on React Native 0.60(+) (see issue #99):

$ cd ios && pod install && cd ..

Tested with React Native version >=0.60

Usage

import ECEncryption from 'react-native-ec-encryption';

const encryptAndThenDecrypt = async () => {
  try {
    //Encrypt
    const cipherText = await ECEncryption.encrypt({
      data: 'some confidential data',
      label: '0x5Cc5dc62be3c95C771C14232e30358B398265deF' //any identical string
    });
    //Decrypt
    const clearText = await ECEncryption.decrypt({
      data: cipherText,
      label: '0x5Cc5dc62be3c95C771C14232e30358B398265deF' //the same identical string
    });
    console.log('decrypt result is ', clearText);
  } catch(e) {
    console.log(e);
  }
};

The library is originally used for Parity Signer.

License

GNU General Public License v3.0