简体   繁体   English

React Native 中的椭圆曲线密码学

[英]Elliptic Curve Cryptography in React Native

Does anyone know if there is an implementation of Elliptic Curve Diffie Hellman cryptography (ECDH) for React Native?有谁知道是否有用于 React Native 的椭圆曲线 Diffie Hellman 密码学(ECDH)的实现?

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 react-native-ecc :它只生成密钥对,不实现从私钥和公钥生成共享密钥(秘密密钥)进行加密
  2. react-native-crypto : it uses some hacks and changes node_modules recursively and i think it's not stable. react-native-crypto :它使用了一些技巧并递归地更改 node_modules,我认为它不稳定。
  3. elliptic : it's in a plain javascript implementation and it does not work in react native椭圆:它是在一个普通的 javascript 实现中,它在本机反应中不起作用

To the best of my knowledge, there is none (in Feb 2020).据我所知,没有(2020 年 2 月)。

In a project that I'm working on, we evaluated known libraries but could not find any for iOS.在我正在进行的一个项目中,我们评估了已知库,但找不到 iOS 的任何库。 Operations that we need include ECDH (with the P-256 curve).我们需要的操作包括 ECDH(使用 P-256 曲线)。

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.它仍在进行中,但我们的想法是在 Swift 中本地构建加密操作,用桥接将它们暴露以填充crypto.subtle API 的缺失部分。

Update: The code is open-source (part of the Cliqz browser for iOS):更新:代码是开源的(iOS 的 Cliqz 浏览器的一部分):

JavaScript (ReactNative): JavaScript(ReactNative):

Swift (native code built on the CryptoKit library): Swift(基于CryptoKit库构建的本机代码):

That was the code to provide the window.crypto.subtle functionality, as you would expect it on a Desktop browser like Firefox or Chrome.这是提供window.crypto.subtle功能的代码,正如您在 Firefox 或 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.请注意 Cliqz 项目已经停止,所以如果你复制粘贴解决方案要小心,因为它不会收到安全补丁。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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