diffie-hellman icon indicating copy to clipboard operation
diffie-hellman copied to clipboard

standalone js file?

Open dicoy-zz opened this issue 7 years ago • 5 comments

I tried running "browserify index.js" to get the actual lib but I doesn't seem to work. It would be awesome if you could show and example of it working to get an idea on how to use it.

dicoy-zz avatar Oct 17 '17 18:10 dicoy-zz

you're going to want to do browserify index.js -s dh which will make the library available under a variable 'dh'

calvinmetcalf avatar Oct 17 '17 19:10 calvinmetcalf

and you'd actually want to do browserify browser.js -s dh

calvinmetcalf avatar Oct 17 '17 19:10 calvinmetcalf

okk, so I did that, and got this as a result: https://codepen.io/dicoy/pen/zEyvXE

I only have the crypto.getRandomValues() function and it won't take any value I give it.

Sorry to bother you so much, but could you show me an example. Something I could paste into the console to see it work, like: var buffer = new ArrayBuffer(12); var x = new DataView(buffer); crypto.getRandomValues(x);

I promise you I'll do something cool with it and credit you properly (I'm planning on mixing it with http://myjson.com/ and doing "serverless" stuff)

dicoy-zz avatar Oct 17 '17 21:10 dicoy-zz

codepen doesn't execute the js in the same context as the console of the page so that's why it doesn't work.

more generally this is meant to work with browserify or webpack so if you build an app with those you can just do require('crypto') and almost all the crypto api is available. so if you're planing on building something bigger that uses this, that would probably be the easier way to do so.

also if your doing stuff in the browsery you almost certainly want to be doing elliptical curve diffie-hellman not the regular kind as this doesn't really scale as well to stronger key size.

calvinmetcalf avatar Oct 18 '17 12:10 calvinmetcalf

if your using ecdh you can also use my other module native-crypto which will use built in browser stuff, once I merge calvinmetcalf/native-crypto#19

calvinmetcalf avatar Oct 18 '17 12:10 calvinmetcalf