ভূমিকা
crypto.pbkdf2() (Password-Based Key Derivation function) ডেরাইভেটিভ ফাংশনের অ্যাসিংক্রোনাস ইমপ্লিমেন্টেশন প্রদান করে। পাসওয়ার্ড, সল্ট এবং ইটারেশন থেকে নির্দিষ্ট অ্যালগরিদমের Hmac ডাইজেস্ট ব্যবহার করে একটি কি ডেরাইভ করা হয়।
সিনট্যাক্স
crypto.createHmac(algorithm, key, [options])
প্যারামিটার
password — রিকোয়েস্টেড বাইট লেন্থের কি পাওয়ার জন্য পাসওয়ার্ড। টাইপ: স্ট্রিং, DataView, Buffer, ইত্যাদি।
salt — পাসওয়ার্ডের মতোই। টাইপ: স্ট্রিং, DataView, Buffer, ইত্যাদি।
iterations — ডিজায়ারড কি পাওয়ার জন্য ইটারেশন। টাইপ: নম্বর।
keylen — কির রিকোয়েস্টেড বাইট লেন্থ। টাইপ: নম্বর।
digest — Hmac অ্যালগরিদম স্পেসিফাই করে। ডিফল্ট: 'sha1'।
callback — অ্যাসিংক্রোনাস মোডে এরর হ্যান্ডলিং।
উদাহরণ ১
pbkdf2.js ফাইল তৈরি করে node pbkdf2.js রান করুন।
// crypto.pbkdf2() demo example // Importing the crypto module const crypto = require('crypto'); // Defining the pbkdf2 with the following options crypto.pbkdf2('secret', 'salt', 100000, 64, 'sha512', (err, derivedKey) => { if (err) throw err; // Printing the derived key console.log("Key Derived: ",derivedKey.toString('hex')); });আউটপুট
C:\home\node>> node pbkdf2.js Key Derived: 3745e482c6e0ade35da10139e797157f4a5da669dad7d5da88ef87e47471cc47ed941c7ad618e8 27304f083f8707f12b7cfdd5f489b782f10cc269e3c08d59ae
উদাহরণ ২
// crypto.pbkdf2() demo example // Importing the crypto module const crypto = require('crypto'); // Defining the pbkdf2 with the following options crypto.pbkdf2('secret', 'salt', 100, 64, 'sha1', (err, derivedKey) => { if (err) throw err; // Printing the derived key console.log("Key Derived: ",derivedKey); console.log("Key Derived in hex: ",derivedKey.toString('hex')); console.log("Key Derived in base64: ",derivedKey.toString('base64')); });আউটপুট
C:\home\node>> node pbkdf2.js Key Derived:Key Derived in hex: b73635f7c0882e1fc3ba6e29b14af1274df84828b4d18fcc222eb574455f505d3d2319132d84e1 91a783e200734e374a24b62cfab65dfb5e9dc28ae147072419 Key Derived in base64: tzY198CILh/Dum4psUrxJ034SCi00Y/MIi61dEVfUF09IxkTLYThkaeD4gBzTjdKJLYs+rZd+16dwo rhRwckGQ==