類:ECDH
添加於:v0.11.14
ECDH
類是用於創建橢圓曲線 Diffie-Hellman (ECDH) key 交換的實用程序。
ECDH
類的實例可以使用
函數創建。crypto.createECDH()
import assert from 'node:assert'; const { createECDH } = await import('node:crypto'); // Generate Alice's keys... const alice = createECDH('secp521r1'); const aliceKey = alice.generateKeys(); // Generate Bob's keys... const bob = createECDH('secp521r1'); const bobKey = bob.generateKeys(); // Exchange and generate the secret... const aliceSecret = alice.computeSecret(bobKey); const bobSecret = bob.computeSecret(aliceKey); assert.strictEqual(aliceSecret.toString('hex'), bobSecret.toString('hex')); // OK
const assert = require('node:assert'); const { createECDH, } = require('node:crypto'); // Generate Alice's keys... const alice = createECDH('secp521r1'); const aliceKey = alice.generateKeys(); // Generate Bob's keys... const bob = createECDH('secp521r1'); const bobKey = bob.generateKeys(); // Exchange and generate the secret... const aliceSecret = alice.computeSecret(bobKey); const bobSecret = bob.computeSecret(aliceKey); assert.strictEqual(aliceSecret.toString('hex'), bobSecret.toString('hex')); // OK
相關用法
- Node.js ECDH.convertKey(key, curve[, inputEncoding[, outputEncoding[, format]]])用法及代碼示例
- Node.js ECDH.setPublicKey(publicKey[, encoding])用法及代碼示例
- Node.js EventEmitter用法及代碼示例
- Node.js Error.message用法及代碼示例
- Node.js Error.stack用法及代碼示例
- Node.js Error.captureStackTrace(targetObject[, constructorOpt])用法及代碼示例
- Node.js EventTarget.addEventListener(type, listener[, options])用法及代碼示例
- Node.js ServerHttp2Stream http2stream.pushStream(headers[, options], callback)用法及代碼示例
- Node.js http2.Http2ServerRequest request.url用法及代碼示例
- Node.js request.socket用法及代碼示例
- Node.js assert.notEqual(actual, expected[, message])用法及代碼示例
- Node.js tlsSocket.authorized用法及代碼示例
- Node.js zlib.deflateRaw()用法及代碼示例
- Node.js http.IncomingMessage message.rawHeaders用法及代碼示例
- Node.js Console用法及代碼示例
- Node.js GM transparent()用法及代碼示例
- Node.js URL.protocol用法及代碼示例
- Node.js http.Agent.reuseSocket(socket, request)用法及代碼示例
- Node.js fs.filehandle.datasync()用法及代碼示例
- Node.js socket.bind()用法及代碼示例
- Node.js v8.getHeapSpaceStatistics()用法及代碼示例
- Node.js http2session.destroyed用法及代碼示例
- Node.js http.ServerResponse response.statusCode用法及代碼示例
- Node.js Buffer buf.writeBigUInt64BE(value[, offset])用法及代碼示例
- Node.js Http2ServerResponse.finished用法及代碼示例
注:本文由純淨天空篩選整理自nodejs.org大神的英文原創作品 ECDH。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。