tradle / react-native-crypto

partial implementation of node's `crypto` for react-native
MIT License
371 stars 84 forks source link

Problem with ECDH keypair generation #7

Closed johnygomez closed 7 years ago

johnygomez commented 8 years ago

Hi, I recently encountered a problem with ECDH initialization. I used the following code:

const ecdh = crypto.createECDH('secp521r1');
const publicKey = ecdh.generateKeys();

however it produces an error

Error: Not implemented yet

I traced the error back to the 'elliptic' lib that uses 'brorand' lib for rand numbers, which contains some old code that throws this error...

I want to ask, whether anybody tried this functionality, and if so, was it working properly?

Thanks.

mvayngrib commented 8 years ago

@johnygomez try the latest https://github.com/mvayngrib/rn-nodeify

i added the getRandomValues shim to shim.js

johnygomez commented 8 years ago

@mvayngrib I'm sorry but it's not working. I think that problem is not in function getRandomValues but in function _rand() in brorand package.. More specifically, Elliptic package calls it here with invalid argument I think.. Can you test the functionality of ECDH please?

mvayngrib commented 8 years ago

@johnygomez seems to work fine here (index.common.js has your two line ecdh example): https://github.com/mvayngrib/rnctest

johnygomez commented 8 years ago

@mvayngrib Sorry, I forgot, that I have to copy the shim.js to the root folder after the update. Now it seems to be working at my app too.. Thanks for now :)

mvayngrib commented 8 years ago

@johnygomez ah yea, i fell for that a few times. Glad you got it working :)