crypto.createECDH()方法是加密模塊的內置應用程序編程接口,用於通過由curveName字符串定義的預定義曲線來創建橢圓曲線Diffie-Hellman即(ECDH) key 交換對象。此外,可以使用crypto.getCurves()方法來返回可用曲線名稱的列表。
用法:
crypto.createECDH( curveName )
參數:此方法接受字符串類型的單個參數curveName。
返回值:它返回ECDH key 交換對象。
以下示例說明了Node.js中crypto.createECDH()方法的使用:
範例1:
// Node.js program to demonstrate the
// crypto.createECDH() method
// Including crypto module
const crypto = require('crypto');
// Creating ECDH with curve name
const curv = crypto.createECDH('secp521r1');
// Prints keys
console.log(curv.generateKeys());
輸出:
<Buffer 04 01 0a cd d0 94 80 31 e8 ... >
範例2:
// Node.js program to demonstrate the
// crypto.createECDH() method
// Including crypto module
const crypto = require('crypto');
// Creating ECDH with curve name
const curv = crypto.createECDH('secp521r1');
curv.generateKeys();
// Prints Public key
console.log("Public Key:", curv.getPublicKey());
// Prints Private Key
console.log("Private Key:", curv.getPrivateKey());
輸出:
Public Key:<Buffer 04 01 68 25 14 c8 ... > Private Key:<Buffer 01 7a ab 4d 71 60 ... >
參考: https://nodejs.org/api/crypto.html#crypto_crypto_createecdh_curvename
相關用法
- Node.js GM drawPolygon()用法及代碼示例
- Node.js GM threshold()用法及代碼示例
- Node.js GM whiteThreshold()用法及代碼示例
- Node.js GM segment()用法及代碼示例
- Node.js GM whitePoint()用法及代碼示例
- Node.js GM write()用法及代碼示例
- Node.js GM quality()用法及代碼示例
注:本文由純淨天空篩選整理自nidhi1352singh大神的英文原創作品 Node.js | crypto.createECDH() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。