crypto.createDiffieHellmanGroup() Method in Node.js

Node.jsJavascriptWeb DevelopmentFront End Technology

The crypto.createDiffieHellmanGroup() is used for creating the DiffieHellmanGroup. This method can also be referred as an alias for crypto.getDiffieHellman.

Syntax

crypto.createDiffieHelmmanGroup(name)

Parameters

The above parameters are described as below −

  • name – It takes the input for the group name. The input is of type 'string'.

Example

Create a file with name – diffieHellmanGroup.js and copy the below code snippet. After creating file, use the following command to run this code as shown in the example below −

node diffieHellmanGroup.js

diffieHellmanGroup.js

 Live Demo

// 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'));

Output

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

Example

Let's take a look at one more example.

 Live Demo

// 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'));

Output

C:\home\node>> node diffieHellmanGroup.js
p3PwqFTpIqOIE3mP+iaMHEosAy8jPCdRDck1HtvbFaMMvJzlfihwzLZB0ZCoEzDRSnlHo+0NjOkNLM
0jM0usS8Ri5wwxw19qwjr00HvxGf0crQtd8ytIVLFX2WWXaT7d8XR/vtw1BUgUVg0mNhKGTLDcVy1A
7CRHzCrDqePaVqnU0QkR2t7S1BvmaMXvkToAdzZnJMPSjZWPVOHzMTOTnpI450TQMLFLv/YGUmKbAO
BaAVbuwfWOHVQrcxgThGGtMRJjjayh0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