@@ -1799,85 +1799,6 @@ If `privateKey` is not valid for the curve specified when the `ECDH` object was
17991799created, an error is thrown. Upon setting the private key, the associated
18001800public point (key) is also generated and set in the ` ECDH ` object.
18011801
1802- ### ` ecdh.setPublicKey(publicKey[, encoding]) `
1803-
1804- <!-- YAML
1805- added: v0.11.14
1806- deprecated: v5.2.0
1807- -->
1808-
1809- > Stability: 0 - Deprecated
1810-
1811- * ` publicKey ` {string|ArrayBuffer|Buffer|TypedArray|DataView}
1812- * ` encoding ` {string} The [ encoding] [ ] of the ` publicKey ` string.
1813-
1814- Sets the EC Diffie-Hellman public key.
1815- If ` encoding ` is provided ` publicKey ` is expected to
1816- be a string; otherwise a [ ` Buffer ` ] [ ] , ` TypedArray ` , or ` DataView ` is expected.
1817-
1818- There is not normally a reason to call this method because ` ECDH `
1819- only requires a private key and the other party's public key to compute the
1820- shared secret. Typically either [ ` ecdh.generateKeys() ` ] [ ] or
1821- [ ` ecdh.setPrivateKey() ` ] [ ] will be called. The [ ` ecdh.setPrivateKey() ` ] [ ] method
1822- attempts to generate the public point/key associated with the private key being
1823- set.
1824-
1825- Example (obtaining a shared secret):
1826-
1827- ``` mjs
1828- const {
1829- createECDH ,
1830- createHash ,
1831- } = await import (' node:crypto' );
1832-
1833- const alice = createECDH (' secp256k1' );
1834- const bob = createECDH (' secp256k1' );
1835-
1836- // This is a shortcut way of specifying one of Alice's previous private
1837- // keys. It would be unwise to use such a predictable private key in a real
1838- // application.
1839- alice .setPrivateKey (
1840- createHash (' sha256' ).update (' alice' , ' utf8' ).digest (),
1841- );
1842-
1843- // Bob uses a newly generated cryptographically strong
1844- // pseudorandom key pair
1845- bob .generateKeys ();
1846-
1847- const aliceSecret = alice .computeSecret (bob .getPublicKey (), null , ' hex' );
1848- const bobSecret = bob .computeSecret (alice .getPublicKey (), null , ' hex' );
1849-
1850- // aliceSecret and bobSecret should be the same shared secret value
1851- console .log (aliceSecret === bobSecret);
1852- ```
1853-
1854- ``` cjs
1855- const {
1856- createECDH ,
1857- createHash ,
1858- } = require (' node:crypto' );
1859-
1860- const alice = createECDH (' secp256k1' );
1861- const bob = createECDH (' secp256k1' );
1862-
1863- // This is a shortcut way of specifying one of Alice's previous private
1864- // keys. It would be unwise to use such a predictable private key in a real
1865- // application.
1866- alice .setPrivateKey (
1867- createHash (' sha256' ).update (' alice' , ' utf8' ).digest (),
1868- );
1869-
1870- // Bob uses a newly generated cryptographically strong
1871- // pseudorandom key pair
1872- bob .generateKeys ();
1873-
1874- const aliceSecret = alice .computeSecret (bob .getPublicKey (), null , ' hex' );
1875- const bobSecret = bob .computeSecret (alice .getPublicKey (), null , ' hex' );
1876-
1877- // aliceSecret and bobSecret should be the same shared secret value
1878- console .log (aliceSecret === bobSecret);
1879- ```
1880-
18811802## Class: ` Hash `
18821803
18831804<!-- YAML
@@ -8147,8 +8068,6 @@ See the [list of SSL OP Flags][] for details.
81478068[ `diffieHellman.generateKeys()` ] : #diffiehellmangeneratekeysencoding
81488069[ `diffieHellman.setPrivateKey()` ] : #diffiehellmansetprivatekeyprivatekey-encoding
81498070[ `diffieHellman.setPublicKey()` ] : #diffiehellmansetpublickeypublickey-encoding
8150- [ `ecdh.generateKeys()` ] : #ecdhgeneratekeysencoding-format
8151- [ `ecdh.setPrivateKey()` ] : #ecdhsetprivatekeyprivatekey-encoding
81528071[ `hash.digest()` ] : #hashdigestencoding
81538072[ `hash.update()` ] : #hashupdatedata-inputencoding
81548073[ `hmac.digest()` ] : #hmacdigestencoding
0 commit comments