5

Does anyone know if there is an implementation of Elliptic Curve Diffie Hellman cryptography (ECDH) for React Native?

I found some libraries for this. each of them has some issues:

  1. react-native-ecc: it only generates key pairs and does not implement generating shared key(secret key) from private and public key for encryption
  2. react-native-crypto: it uses some hacks and changes node_modules recursively and i think it's not stable.
  3. elliptic : it's in a plain javascript implementation and it does not work in react native
Emad Bayat
  • 177
  • 1
  • 2
  • 12
  • To add one more non-solution, [noble-secp256k1](https://www.npmjs.com/package/noble-secp256k1) depends on the `BigInt` class and uses `n` big integer suffix syntax. – Diomidis Spinellis Aug 15 '21 at 13:29
  • Also note that [react-native-crypto](https://www.npmjs.com/package/react-native-crypto) internally depends on [create-ecdh](https://www.npmjs.com/package/create-ecdh), which in non-node environments is a wrapper around [elliptic](https://www.npmjs.com/package/elliptic) whose [brorand](https://www.npmjs.com/package/brorand)-based random number generation fails on React Native. – Diomidis Spinellis Aug 15 '21 at 16:13

1 Answers1

2

To the best of my knowledge, there is none (in Feb 2020).

In a project that I'm working on, we evaluated known libraries but could not find any for iOS. Operations that we need include ECDH (with the P-256 curve).

It is still work in progress, but our idea is to build the crypto operations natively in Swift, expose them with a bridge to fill in the missing parts of the crypto.subtle API.

Update: The code is open-source (part of the Cliqz browser for iOS):

JavaScript (ReactNative):

Swift (native code built on the CryptoKit library):

That was the code to provide the window.crypto.subtle functionality, as you would expect it on a Desktop browser like Firefox or Chrome. To see how it was used, you can look at the actual usage, or - maybe easier - at the commented-out example.

I'll added the links here in the hope that it provides entry points for someone facing the same problem. Please note that the Cliqz project has been discontinued, so be careful if you copy-paste the solution, as it will not receive security patches.

Philipp Claßen
  • 41,306
  • 31
  • 146
  • 239