How to use the createECDH function from crypto

Find comprehensive JavaScript crypto.createECDH code examples handpicked from public code repositorys.

263
264
265
266
267
268
269
270
271
272
273
274
const availableHashes = new Set(crypto.getHashes());


// Oakley curves do not clean up ERR stack, it was causing unexpected failure
// when accessing other OpenSSL APIs afterwards.
if (availableCurves.has('Oakley-EC2N-3')) {
  crypto.createECDH('Oakley-EC2N-3');
  crypto.createHash('sha256');
}


// Test ECDH
fork icon0
star icon0
watch icon0

+ 55 other calls in file

356
357
358
359
360
361
362
363
364
365
	'nistp256': 'prime256v1',
	'nistp384': 'secp384r1',
	'nistp521': 'secp521r1'
}[curve];

var dh = crypto.createECDH(osCurve);
dh.generateKeys();

parts.push({name: 'curve',
    data: Buffer.from(curve)});
fork icon0
star icon0
watch icon0

+ 3 other calls in file

389
390
391
392
393
394
395
396
397
398

Creates a `DiffieHellman` key exchange object and generates a prime of
`prime_length` bits using an optional specific numeric `generator`.
If `generator` is not specified, the value `2` is used.

### crypto.createECDH(curve_name)

Creates an Elliptic Curve Diffie-Hellman (`ECDH`) key exchange object using a
predefined curve specified by the `curve_name` string. Use
[`crypto.getCurves()`][] to obtain a list of available curve names. On recent
fork icon0
star icon0
watch icon1