Node.js 中的 crypto.createDiffieHellmanGroup() 方法
将被用于创建DiffieHellmanGroup。此方法也可以称为crypto.getDiffieHellman的别名。crypto.createDiffieHellmanGroup()
语法
crypto.createDiffieHelmmanGroup(name)
参数
上述参数描述如下-
name -它接受组名的输入。输入是“字符串”类型。
示例
创建一个具有名称的文件-diffieHellmanGroup.js并复制以下代码片段。创建文件后,使用以下命令运行此代码,如下例所示-
node diffieHellmanGroup.js
diffieHellmanGroup.js
//crypto.createDiffieHellmanGroupDemo示例 //导入加密模块 const crypto = require('crypto'); //定义组名 const name = 'modp1'; //创建DiffieHellman组 var diffieHellmanGroup = crypto.createDiffieHellmanGroup(name); //显示上述组的编码密钥 console.log(diffieHellmanGroup.generateKeys('hex'));输出结果
C:\home\node>> node diffieHellmanGroup.js 55963b8969c6b5d67dc7a2d80e6bcbea55bdb50000661c8d6e026be5366619edb9971755942fd8 fa5cba5d66a0326db9957d0ff412bfe22ee2431398206b97210b86c802e1be6777bce3d6cf735f bb3c7cdee4016db9d252a66be82d58158a21
示例
让我们再看一个例子。
//crypto.createDiffieHellmanGroupDemo示例 //导入加密模块 const crypto = require('crypto'); //定义组名 const name = 'modp17'; //创建DiffieHellman组 var diffieHellmanGroup = crypto.createDiffieHellmanGroup(name); //显示上述组的编码密钥 console.log(diffieHellmanGroup.generateKeys('base64'));输出结果
C:\home\node>> node diffieHellmanGroup.js p3PwqFTpIqOIE3mP+iaMHEosAy8jPCdRDck1HtvbFaMMvJzlfihwzLZB0ZCoEzDRSnlHo+0NjOkNLM 0jM0usS8Ri5wwxw19qwjr00HvxGf0crQtd8ytIVLFX2WWXaT7d8XR/vtw1BUgUVg0mNhKGTLDcVy1A 7CRHzCrDqePaVqnU0QkR2t7S1BvmaMXvkToAdzZnJMPSjZWPVOHzMTOTnpI450TQMLFLv/YGUmKbAO BaAVbuwfWOHVQrcxgThGGtMRJjjayh0Q77RmoqpKcMWceJPlQhFIMG/jFrNEaacbgb0Ctnm1/d1UgE UTIg0phE4/1GX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