Node.js 中的 crypto.createDiffieHellmanGroup() 方法


crypto.createDiffieHellmanGroup() 用于创建 DiffieHellmanGroup。此方法还可以作为 crypto.getDiffieHellman 的别名。

语法

crypto.createDiffieHelmmanGroup(name)

参数

以上参数描述如下 −

  • name – 输入组名。输入类型为“字符串”。

示例

创建一个名为 diffieHellmanGroup.js 的文件,并复制以下代码段。创建文件后,使用以下命令运行此代码,如下例所示 −

node diffieHellmanGroup.js

diffieHellmanGroup.js

 实时演示

// crypto.createDiffieHellmanGroup Demo Example

// Importing the crypto module
const crypto = require('crypto');

// Defining the group name
const name = 'modp1';

// Creating DiffieHellman group
var diffieHellmanGroup = crypto.createDiffieHellmanGroup(name);

// Displaying the encoded keys for the above group
console.log(diffieHellmanGroup.generateKeys('hex'));

输出

C:\home
ode>> node diffieHellmanGroup.js 55963b8969c6b5d67dc7a2d80e6bcbea55bdb50000661c8d6e026be5366619edb9971755942fd8 fa5cba5d66a0326db9957d0ff412bfe22ee2431398206b97210b86c802e1be6777bce3d6cf735f bb3c7cdee4016db9d252a66be82d58158a21

示例

我们来看另一个示例。

 实时演示

// crypto.createDiffieHellmanGroup Demo Example

// Importing the crypto module
const crypto = require('crypto');

// Defining the group name
const name = 'modp17';

// Creating DiffieHellman group
var diffieHellmanGroup = crypto.createDiffieHellmanGroup(name);

// Displaying the encoded keys for the above group
console.log(diffieHellmanGroup.generateKeys('base64'));

输出

C:\home
ode>> node diffieHellmanGroup.js p3PwqFTpIqOIE3mP+iaMHEosAy8jPCdRDck1HtvbFaMMvJzlfihwzLZB0ZCoEzDRSnlHo+0NjOkNLM 0jM0usS8Ri5wwxw19qwjr00HvxGf0crQtd8ytIVLFX2WWXaT7d8XR/vtw1BUgUVg0mNhKGTLDcVy1A 7CRHzCrDqePaVqnU0QkR2t7S1BvmaMXvkToAdzZnJMPSjZWPVOHzMTOTnpI450TQMLFLv/YGUmKbAO BaAVbuwfWOHVQrcxgThGGtMRJjjayh0Q77RmoqpKcMWceJPlQhFIMG/jFrNEaacbgb0Ctnm1/d1UgE UTIg0phE4/1GXdnEDRPGVXURaxzPU+N48QVAB7Dyzpcq4k2f/mARLILPufEP/8FBawmMDoyAE4PS/Z 1RFwwuInhdbhgxTTRV+nkzSwTt0V51q+B9fek2xDfeWDqwibr+OWdU0DXs07mUsFVJdVJSZFM7txIg UYH/6Tb+EnIt//JVR7hUrphWFhZCE1+7AcrHfNNX/lq8ukTNU+Bh6A9c1g9Ua2MjGXGLADAw7S7Hvq OfVWy/f9JAbxt6bIz7LswioLGsaeKuEhGOxK8WRkeIbf1wbKF4kZQC8Q1V4XHFXI0wQ/Qhc7yyOZUc /lwGsUnCqVR+Fqibd1YHk5vcaUfnQMIyvwAXtRBKz49PLc6/V4deDX/243zCe1UucxPodjuyYbRwx0 9Kqr8yT7fVkctF+eQNSOCABDpykwPxz/P2X6Tq9NW4KcOm0uZ+39AVWl7pMmLb8rf8VKJQLCGUoMYl XEwG0XnERJk4AmxDWOICFDcgVrXhJn5OyJzysc9gYOlMrlEVpJzk55lz1JXld6mSk3YMrGZyDE2OHH SzDx9EWpH8MJZpdPtDQ3/njptVM7m9i76fM7x5irqo+tonOy2myJPVBOl9gcMs556p7p0MRWVmi0AP ulIONRicQeMjHxFR5Di8RDjfXrHz66CFJa9vEzhKNMZDQon2XdZlzgxr35cFdRIQNQq1zeGGzny7N4 03NGbPZP5b

更新于: 2021-05-20

89 次浏览

开启你的职业生涯

完成课程获得认证

开始
广告