Node.js crypto.createDiffieHellmanGroup() Method
Last Updated :
31 Mar, 2023
The crypto.createDiffieHellmanGroup() method is an inbuilt application programming interface of the crypto module which is used to create a DiffieHellmanGroup.
Syntax:
crypto.createDiffieHellmanGroup( name )
Parameters: This method accepts single parameters name which is of type string.
Return Value: It returns the DiffieHellmanGroup.
The below examples illustrate the use of crypto.createDiffieHellmanGroup() method in Node.js:
Example 1:
javascript
const crypto = require( 'crypto' );
const name = 'modp1' ;
let diffHell = crypto.createDiffieHellmanGroup(name);
console.log(diffHell.generateKeys( 'hex' ));
|
Output:
ace9c0ae947385ecd238d02e9e6431a8ceb7fd295c88271ba53e46026116d651898d498ea94980cc35a79e7254f02690a8e4b184cd0a7aecad97f77626741423f3b2f2eeb7b0de9a1fa35e22415ed1aae16860a9910528813dd852af5a36700b
Example 2:
javascript
const crypto = require( 'crypto' );
const name = 'modp15' ;
let diffHell = crypto.createDiffieHellmanGroup(name);
console.log(diffHell.generateKeys( 'base64' ));
|
Output:
vkznZVRMdtS/3I9+cMfXQygigYhfbvo56xk5i3dYpsEnOFJVpcxzK4JEGChsO1cLHsbIKF1nS0hMuxzvfoMrOh6QyOT3Ptp/cmnGAwmRiKkOhpg6mWDUwMN1bxO+SQSUPAEWaRV8ub2wHb3dCxapGCGovuY+7AbrZO4DmIwYHULG01C3gQtLps74q/absa8orsOBW4Dcz/KNaw3njbBrHXnHOpyWiFYasgBz2YwQien8f9zeiAn1CjEbkfGysYdycqzfqBDuW19rDRDPINt1YJqrR5fpsbVjPJOmUNYKoTtk6VqEEx4y48j+f/z/qEOotjRDKJLAi4y7TmFCCfuetTVTn/b2PVGsKK+/rw2GYQZFOgZh/wYhk2UppKkrfBU2a0uBGU6Oo29N/BqgOU3pTZKCR+IXQdLOGJLYOjUo3VVsQbZi0WS9zt6YFwn3HtffkVYF/71lImA2RxZlrGgsPM7B/AytFqd0bVJ4h5ql0OKf/mvWdE2OPEhTRrpeWe5+
Reference: https://nodejs.org/api/crypto.html#crypto_crypto_creatediffiehellmangroup_name
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...