crypto.getDiffieHellman(groupName)
添加於:v0.7.5
參數
groupName
<string>- 返回: <DiffieHellmanGroup>
創建一個預定義的DiffieHellmanGroup
key 交換對象。支持的組是:'modp1'
、'modp2'
、'modp5'
(在 RFC 2412 中定義,但參見 Caveats)和 'modp14'
、'modp15'
、'modp16'
、'modp17'
、 'modp18'
(在 RFC 3526 中定義)。返回的對象模仿由
創建的對象的接口,但不允許更改鍵(例如,使用 crypto.createDiffieHellman()
)。使用這種方法的優點是雙方不必事先生成或交換組模數,從而節省了處理器和通信時間。diffieHellman.setPublicKey()
示例(獲取共享 key ):
const { getDiffieHellman } = await import('node:crypto'); const alice = getDiffieHellman('modp14'); const bob = getDiffieHellman('modp14'); alice.generateKeys(); bob.generateKeys(); const aliceSecret = alice.computeSecret(bob.getPublicKey(), null, 'hex'); const bobSecret = bob.computeSecret(alice.getPublicKey(), null, 'hex'); /* aliceSecret and bobSecret should be the same */ console.log(aliceSecret === bobSecret);
const { getDiffieHellman, } = require('node:crypto'); const alice = getDiffieHellman('modp14'); const bob = getDiffieHellman('modp14'); alice.generateKeys(); bob.generateKeys(); const aliceSecret = alice.computeSecret(bob.getPublicKey(), null, 'hex'); const bobSecret = bob.computeSecret(alice.getPublicKey(), null, 'hex'); /* aliceSecret and bobSecret should be the same */ console.log(aliceSecret === bobSecret);
相關用法
- Node.js crypto.getDiffieHellman()用法及代碼示例
- Node.js crypto.getCurves()用法及代碼示例
- Node.js crypto.getHashes()用法及代碼示例
- Node.js crypto.getCiphers()用法及代碼示例
- Node.js crypto.generateKeyPairSync(type, options)用法及代碼示例
- Node.js crypto.generateKeyPair()用法及代碼示例
- Node.js crypto.generateKeyPair(type, options, callback)用法及代碼示例
- Node.js crypto.generateKeyPairSync()用法及代碼示例
- Node.js crypto.generateKeySync(type, options)用法及代碼示例
- Node.js crypto.generateKey(type, options, callback)用法及代碼示例
- Node.js crypto.randomFill()用法及代碼示例
- Node.js crypto.createHmac()用法及代碼示例
- Node.js crypto.randomFillSync(buffer[, offset][, size])用法及代碼示例
- Node.js crypto.constants用法及代碼示例
- Node.js crypto.randomInt([min, ]max[, callback])用法及代碼示例
- Node.js crypto.publicEncrypt()用法及代碼示例
- Node.js crypto.publicDecrypt()用法及代碼示例
- Node.js crypto.pbkdf2Sync(password, salt, iterations, keylen, digest)用法及代碼示例
- Node.js crypto.createHash()用法及代碼示例
- Node.js crypto.hkdfSync()用法及代碼示例
- Node.js crypto.randomFillSync()用法及代碼示例
- Node.js crypto.checkPrime()用法及代碼示例
- Node.js crypto.sign()用法及代碼示例
- Node.js crypto.webcrypto用法及代碼示例
- Node.js crypto.createCipheriv()用法及代碼示例
注:本文由純淨天空篩選整理自nodejs.org大神的英文原創作品 crypto.getDiffieHellman(groupName)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。