browserify / diffie-hellman

pure js diffie-hellman
MIT License
95 stars 26 forks source link

standalone js file? #25

Open dicoy-zz opened 7 years ago

dicoy-zz commented 7 years ago

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.

calvinmetcalf commented 7 years ago

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

calvinmetcalf commented 7 years ago

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

dicoy-zz commented 7 years ago

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)

calvinmetcalf commented 7 years ago

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 commented 7 years ago

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