From 5d9c35c3a68ed6e343660aa76c660d944af57c3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Thu, 30 Aug 2018 23:48:12 +0200 Subject: [PATCH 1/2] doc: improve ECDH example --- doc/api/crypto.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/api/crypto.md b/doc/api/crypto.md index f77f4213beb5fb..7066ab23327885 100644 --- a/doc/api/crypto.md +++ b/doc/api/crypto.md @@ -703,18 +703,18 @@ If the `inputEncoding` is not provided, `key` is expected to be a [`Buffer`][], Example (uncompressing a key): ```js -const { ECDH } = require('crypto'); +const crypto = require('crypto'); -const ecdh = ECDH('secp256k1'); +const ecdh = crypto.createECDH('secp256k1'); ecdh.generateKeys(); const compressedKey = ecdh.getPublicKey('hex', 'compressed'); -const uncompressedKey = ECDH.convertKey(compressedKey, - 'secp256k1', - 'hex', - 'hex', - 'uncompressed'); +const uncompressedKey = crypto.ECDH.convertKey(compressedKey, + 'secp256k1', + 'hex', + 'hex', + 'uncompressed'); // the converted key and the uncompressed public key should be the same console.log(uncompressedKey === ecdh.getPublicKey('hex')); From 10cf2a8b1ed67987b03c04b1b39b53d4e3e5f951 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Fri, 31 Aug 2018 10:48:59 +0200 Subject: [PATCH 2/2] Update crypto.md --- doc/api/crypto.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/api/crypto.md b/doc/api/crypto.md index 7066ab23327885..410eed1a5daf70 100644 --- a/doc/api/crypto.md +++ b/doc/api/crypto.md @@ -703,18 +703,18 @@ If the `inputEncoding` is not provided, `key` is expected to be a [`Buffer`][], Example (uncompressing a key): ```js -const crypto = require('crypto'); +const { createECDH, ECDH } = require('crypto'); -const ecdh = crypto.createECDH('secp256k1'); +const ecdh = createECDH('secp256k1'); ecdh.generateKeys(); const compressedKey = ecdh.getPublicKey('hex', 'compressed'); -const uncompressedKey = crypto.ECDH.convertKey(compressedKey, - 'secp256k1', - 'hex', - 'hex', - 'uncompressed'); +const uncompressedKey = ECDH.convertKey(compressedKey, + 'secp256k1', + 'hex', + 'hex', + 'uncompressed'); // the converted key and the uncompressed public key should be the same console.log(uncompressedKey === ecdh.getPublicKey('hex'));