ভূমিকা
crypto.createDiffieHellmanGroup() একটি প্রি-ডিটারমিন্ড DiffieHellmanGroup কি এক্সচেঞ্জ অবজেক্ট তৈরি করতে ব্যবহৃত হয়। সাপোর্টেড গ্রুপগুলো: modp1, modp2, modp5, modp 14, modp16, modp17 ইত্যাদি। এই মেথডের সুবিধা হলো পার্টিগুলোকে গ্রুপ মডুলাস জেনারেট বা এক্সচেঞ্জ করতে হয় না, যা প্রসেসিং টাইম বাঁচায়।
সিনট্যাক্স
crypto.getDiffieHelmmanGroup(groupName)
প্যারামিটার
groupName — গ্রুপের নাম। ইনপুট টাইপ: 'string'।
উদাহরণ ১
getdiffieHellman.js ফাইল তৈরি করে node getDiffieHellman.js রান করুন।
// crypto.getDiffieHellman() Demo Example // Importing the crypto module const crypto = require('crypto'); const server = crypto.getDiffieHellman('modp1'); const client = crypto.getDiffieHellman('modp1'); // Printing DiffieHellman values console.log(server); console.log(client); // Generating public and private keys server.generateKeys(); client.generateKeys(); // Gettong public key const serverSecret = server.computeSecret(client.getPublicKey(), null, 'hex'); const clientSecret = client.computeSecret(server.getPublicKey(), null, 'hex'); /* aliceSecret and bobSecret should be the same */ console.log(serverSecret === clientSecret);আউটপুট
C:\home\node>> node getDiffieHellman.js DiffieHellmanGroup { _handle: { verifyError: [Getter] }, verifyError: 0 } DiffieHellmanGroup { _handle: { verifyError: [Getter] }, verifyError: 0 } trueউদাহরণ ২ (এরর কেস)
// crypto.getDiffieHellman() Demo Example // Importing the crypto module const crypto = require('crypto'); const dh1 = crypto.getDiffieHellman('modp17'); const dh2 = crypto.getDiffieHellman('modp14'); // Generating public and private keys dh1.generateKeys(); dh2.generateKeys(); // Gettong public key const dh1Key = dh1.computeSecret(dh2.getPublicKey(), null, 'hex'); const dh2Key = dh2.computeSecret(dh1.getPublicKey(), null, 'hex'); /* aliceSecret and bobSecret should be the same */ console.log(dh1Key === dh2Key);আউটপুট
C:\home\node>> node getDiffieHellman.js internal/crypto/diffiehellman.js:102 const ret = this._handle.computeSecret(toBuf(key, inEnc)); ^ Error: Supplied key is too large at DiffieHellmanGroup.dhComputeSecret [as computeSecret] (internal/crypto/diffiehellman.js:102:28) ...
ভিন্ন গ্রুপের কি ব্যবহার করলে এরর হয়।