Elliptic Curve Diffie-Hellman and AES Example in Node.JS

Recently I learned how to generate shared secrets using ECDH in Node.JS, but I still had to know how to use this shared secret. Here is one application for it. Use the ECDH to generate a shared secret and then use that shared secret to cipher/decipher messages between both parties, in this case Joe and Zoe. Here is the code: …

How to generate Diffie Hellman key pair in Node.JS

Super easy using crypto library. You can create a file called¬†DiffieHellmanKeyPairGeneration.js for example and paste this code inside: console.log(‘\n- — ( Diffie Hellman Key Pair Generator ) — -‘); var crypto = require(‘crypto’); var bitSize = 2048; var dh = crypto.createDiffieHellman(bitSize); dh.generateKeys(); console.log(‘Private Key:\n’ + dh.getPrivateKey(‘base64’)); console.log(‘\n’); console.log(‘Public Key:\n’ + dh.getPublicKey(‘base64’)); console.log(‘— End —‘); Then run it, wait…wait…wait…wait…wait…wait…, and you …