DiffieHellmanGroup 类


DiffieHellmanGroup 类以著名的 modp 组为参数。 它的工作原理与 DiffieHellman 相同,不同之处在于它不允许在创建后更改其密钥。 换句话说,它没有实现 setPublicKey()setPrivateKey() 方法。

const { createDiffieHellmanGroup } = await import('node:crypto');
const dh = createDiffieHellmanGroup('modp16');const { createDiffieHellmanGroup } = require('node:crypto');
const dh = createDiffieHellmanGroup('modp16');

支持以下组:

  • 'modp14'(2048 位,RFC 3526 第 3 节)
  • 'modp15'(3072 位,RFC 3526 第 4 节)
  • 'modp16'(4096 位,RFC 3526 第 5 节)
  • 'modp17'(6144 位,RFC 3526 第 6 节)
  • 'modp18'(8192 位,RFC 3526 第 7 节)

以下组仍受支持但已弃用(请参阅 注意事项):

  • 'modp1'(768 位,RFC 2409 第 6.1 节)
  • 'modp2'(1024 位,RFC 2409 第 6.2 节)
  • 'modp5'(1536 位,RFC 3526 第 2 节)

这些已弃用的组可能会在 Node.js 的未来版本中被删除。

The DiffieHellmanGroup class takes a well-known modp group as its argument. It works the same as DiffieHellman, except that it does not allow changing its keys after creation. In other words, it does not implement setPublicKey() or setPrivateKey() methods.

const { createDiffieHellmanGroup } = await import('node:crypto');
const dh = createDiffieHellmanGroup('modp16');const { createDiffieHellmanGroup } = require('node:crypto');
const dh = createDiffieHellmanGroup('modp16');

The following groups are supported:

  • 'modp14' (2048 bits, RFC 3526 Section 3)
  • 'modp15' (3072 bits, RFC 3526 Section 4)
  • 'modp16' (4096 bits, RFC 3526 Section 5)
  • 'modp17' (6144 bits, RFC 3526 Section 6)
  • 'modp18' (8192 bits, RFC 3526 Section 7)

The following groups are still supported but deprecated (see Caveats):

  • 'modp1' (768 bits, RFC 2409 Section 6.1)
  • 'modp2' (1024 bits, RFC 2409 Section 6.2)
  • 'modp5' (1536 bits, RFC 3526 Section 2)

These deprecated groups might be removed in future versions of Node.js.