cryptography - Computing a ECDH Shared Secret in JavaScript -


I need to calculate a shared secret in JavaScript using the ECC key ECDH key. I can see two potential projects that can do this, but I'm not sure if anyone chases. 1) Chrome extension, so I think it means that it is not going to run in other browsers. 2) There was a problem with a person's SGCL, in which he thought it was using ECMQV instead of plain ECD (H).

Can someone advise me to do a good course for my implementation? And option 3 (a preferred option): I have a garbage that could be directly to include the shared sharing implementation.

This is the C ++ code for creating shared secrets on the server:

  zero * ecies_key_derivation (const zero * input, size_t ilen, zero * output, Size_t * olen) {* olen = SHA512_DIGEST_LENGTH; Return (Zero *) SHA512 ((Konest unsigned 4 *) Input, Ilan, (unsigned char *) output); } ... FC :: sha512 shared_secret; ECDH_compute_key ((unsigned char *) and shared_cent, size (shared_ secret), EC_KEY_get0_public_key (recipient- my- & gt; _key), my-> _key, ecies_key_derivation);  

Obviously this should be seamless, but it's working at least!

Option 1 Chrome is specific: "Correspondence on the code (git clon-enabled git clone), and it seems Chrome is designed to be an add-on only"

Option 2 seen using Bit 2 works (uses SJLL behind bitcore scenario):

  # NMP install bitscore ECIES = '../node_modules/ Bitcore / lib / ECIES 'ot_pubkey = new buffer is required (Onetime_public_key,' hex ') my_privkey = new buffer (d_receiver_hex,' hex ') Christian = new ECIES.encryptObj ot_pubkey, new buffer (' '), My_privkey s = ecies.getSfromPubkey () console.log' bitcore sharedsecret \ t ', ST string' hex 'S_kdf_buf = ECIES.kdf (s) console.log' bitcore shared kdf \ t ', S_kdf_buf.toString 'Hex'  

Alternate addition to this For a large number it has its own code (bn.js) (the same author):

  #GIT clone https://github.com/indutny/elliptic.git altaptic = expected ('../ elliptic / lib / elliptic.js') # Install NPM bn.js bn = require ('bn.js') # Providing Ecies_key_derivation https://github.com/indutny/elliptic/issues/9 Ec = new elliptic.ec ('secp256k1') s0 = ec.keyPair (onetime_private_key, 'hex') # ../testnet/config/genesis_private_keys Txt s1 = ec.keyPair (d_receiver_hex, "hex") sh0 = s0.derive (s1.getPublic ()) sh1 = s1.derive (s0.getPublic ()) assert.equal sh0.toString (16), sh1.toString (16), "Shared secrets not found" shared_secret = "0" + sh0.toString (16) #### Only works for this shared secret (bn.js :: toString (16))  

At this point, I have met these libraries to produce shared secrets correctly and I ended up using crypto-js for decryption.

  # https://code.google.com/p/crypto-js/#Custom_Key_and_IV # See wallet_records.cpp master_key :: decrypt_key CryptoJS AES.d Decrypt (cipher text: cipher salt: empty , @key, iv: @iv)  

For decryption, I need a 256 bit IV (initial vector) for the task, leaving SJCL until this update Is not done (). Along with that, I did not have much luck to decrypt with Albic.JS, although I'm not sure it was my fault.


Comments