Skip to content

Instantly share code, notes, and snippets.

@billautomata
Created December 26, 2015 19:46
Show Gist options
  • Save billautomata/5a36b1cde9b5aa6972a9 to your computer and use it in GitHub Desktop.
Save billautomata/5a36b1cde9b5aa6972a9 to your computer and use it in GitHub Desktop.
createDiffieHellman derps
var assert = require('assert')
var crypto = require('crypto')
var fs = require('fs')
var alice = crypto.createDiffieHellman(2048)
alice.setPrivateKey(fs.readFileSync('../alice.private.pem').toString('hex'),'hex')
alice.setPublicKey(fs.readFileSync('../alice.public.pem').toString('hex'),'hex')
var bob = crypto.createDiffieHellman(2048)
bob.setPrivateKey(fs.readFileSync('../bob.private.pem').toString('hex'),'hex')
bob.setPublicKey(fs.readFileSync('../bob.public.pem').toString('hex'),'hex')
console.log(alice.computeSecret(bob.getPublicKey('base64'), 'base64', 'base64'))
#!/bin/env bash
# generate parameters for each person
openssl genpkey -genparam -algorithm DH -pkeyopt dh_rfc5114:2 -out params.diffie.alice.pem
openssl genpkey -genparam -algorithm DH -pkeyopt dh_rfc5114:2 -out params.diffie.bob.pem
# generate the private keys for each person
openssl genpkey -paramfile params.diffie.alice.pem -out alice.private.pem
openssl genpkey -paramfile params.diffie.alice.pem -out bob.private.pem
# generate the public keys for each person
openssl pkey -in alice.private.pem -pubout -out alice.public.pem
openssl pkey -in bob.private.pem -pubout -out bob.public.pem
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment