Crypto.createDiffieHellmanGroup(primeLength, [generator]) विधि का उपयोग एक प्रमुख एक्सचेंज ऑब्जेक्ट बनाने के लिए किया जाता है जो एक संख्यात्मक जनरेटर का उपयोग करके प्राइमलेंथ बिट्स की एक प्रमुख संख्या उत्पन्न करता है। जनरेटर परिभाषित नहीं होने पर डिफ़ॉल्ट मान 2 होता है।
सिंटैक्स
crypto.createDiffieHelmmanGroup(primeLength, [generator])
पैरामीटर
उपरोक्त पैरामीटर नीचे वर्णित हैं -
-
प्राइम लेंथ - उत्पन्न होने वाले प्राइम बिट्स की संख्या। इनपुट मान प्रकार संख्या का है।
-
जनरेटर - एक्सचेंज की ऑब्जेक्ट जेनरेट करने के लिए जेनरेटर। डिफ़ॉल्ट मान:2.
उदाहरण
index.js नाम से एक फाइल बनाएं और नीचे दिए गए कोड स्निपेट को कॉपी करें। फ़ाइल बनाने के बाद, इस कोड को चलाने के लिए निम्न कमांड का उपयोग करें जैसा कि नीचे दिए गए उदाहरण में दिखाया गया है -
node index.js
index.js
// crypto.createDiffieHellman(primeLength, [generator]) Demo Example
// Importing the crypto module
const crypto = require('crypto');
// Initializing the variable primeLength
var primeLength = 29;
// Creating DiffieHellman keyexchange object
var exchangeKey = crypto.createDiffieHellman(primeLength);
// Printing the exchange keys
console.log("DiffieHellman key is: " + exchangeKey.generateKeys('base64')); आउटपुट
C:\home\node>> node index.js DiffieHellman key is: BaRoaA==
उदाहरण
आइए एक और उदाहरण देखें।
// crypto.createDiffieHellman(primeLength, [generator]) Demo Example
// Importing the crypto module
const crypto = require('crypto');
// Initializing the variable primeLength
var primeLength = 29;
var generator = 3; //Default value is 2
// Creating DiffieHellman keyexchange object
var exchangeKey = crypto.createDiffieHellman(primeLength, generator);
// Printing the exchange keys
console.log("DiffieHellman keys are: " + exchangeKey.generateKeys('hex'));
// Displays public and private keys
console.log("Public Key is: ",
exchangeKey.getPublicKey('hex'));
console.log("Private Key: ",
exchangeKey.getPrivateKey('hex')); आउटपुट
C:\home\node>> node index.js DiffieHellman keys are: 1a21670d Public Key is: 1a21670d Private Key: 0d4a1a3c