简体   繁体   中英

Elliptic Curve Cryptography in React Native

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM