ভূমিকা
cipher.update() প্রদত্ত ডেটা এবং এনকোডিং ফরম্যাট অনুযায়ী সাইফার আপডেট করতে ব্যবহৃত হয়। এটি crypto মডিউলের Cipher ক্লাসের একটি বিল্ট-ইন মেথড। ইনপুট এনকোডিং স্পেসিফাই থাকলে data আর্গুমেন্ট স্ট্রিং, নাহলে বাফার।
সিনট্যাক্স
cipher.update(data, [inputEncoding], [outputEncoding])
প্যারামিটার
data — সাইফার কন্টেন্ট আপডেট করার জন্য ইনপুট ডেটা।
inputEncoding — ইনপুট এনকোডিং। সম্ভব মান: hex, base64, ইত্যাদি।
outputEncoding — আউটপুট এনকোডিং। ইনপুট টাইপ: স্ট্রিং। সম্ভব মান: hex, base64, ইত্যাদি।
উদাহরণ ১
cipherUpdate.js ফাইল তৈরি করে node cipherUpdate.js রান করুন।
// Example to demonstrate the use of cipher.final() method // Importing the crypto module const crypto = require('crypto'); // Initialising the AES algorithm const algorithm = 'aes-192-cbc'; // Initialising the password used for generating key const password = '12345678123456789'; // Retrieving key for the cipher object const key = crypto.scryptSync(password, 'old data', 24); // Initializing the static iv const iv = Buffer.alloc(16, 0); // Initializing the cipher object to get cipher const cipher = crypto.createCipheriv(algorithm, key, iv); //Getting the updated string value with new data let updatedValue = cipher.update('Welcome to tutorials point', 'utf8', 'hex'); //Adding the old value and updated value updatedValue += cipher.final('hex'); // Printing the result... console.log("Updated String:- " + updatedValue);আউটপুট
C:\home\node>> node cipherUpdate.js Updated String:- a05e87569f3f04234812ae997da5684944c32b8776fae676b4abe9074b31cd2a
উদাহরণ ২
// Example to demonstrate the use of cipher.final() method // Importing the crypto module const crypto = require('crypto'); // Initialising the AES algorithm const algorithm = 'aes-192-cbc'; // Initialising the password used for generating key const password = '12345678123456789'; // Retrieving key for the cipher object crypto.scrypt(password, 'salt', 24, { N: 512 }, (err, key) => { if (err) throw err; // Initializing the static iv const iv = Buffer.alloc(16, 0); // Initializing the cipher object to get cipher const cipher = crypto.createCipheriv(algorithm, key, iv); //Getting the updated string value with new data let updatedValue = cipher.update('Some new text data', 'utf8', 'hex'); //Adding the old value and updated value updatedValue += cipher.final('hex'); // Printing the result... console.log("Updated String:- " + updatedValue); });আউটপুট
C:\home\node>> node cipherUpdate.js Updated String:- 91d6d37e70fbae537715f0a921d15152194435b96ce3973d92fbbc4a82071074