

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Node.js – hmac.update() Method
The Hmac class is one of the many utility classes that is used for creating the cryptographic HMAC digests. The Hmac.update() method is used for updating the Hmac content with the data passed. If encoding is not provided and the data is in string format, then the default encoding 'utf8' is enforced.
Syntax
hmac.update(data, [encoding])
Parameters
The parameters are described below:
- data − This input parameter takes input for the data with which Hmac will be updated.
- encoding − This input parameter takes input for the encoding to be considered while updating the Hmac.
Example 1
Create a file with the name "hmacUpdate.js" and copy the following code snippet. After creating the file, use the command "node hmacUpdate.js" to run this code.
// Hmac.digest() Demo Example // Importing the crypto module const crypto = require("crypto") // Initializing the Hmac object with encoding and key const hmac = crypto.createHmac('sha256', 'secretKey'); // Updating hmac with below data hmac.update('Welcome'); hmac.update('To'); hmac.update('TutorialsPoint') // Printing the hmac value using digests console.log("Hmac is: " + hmac.digest('hex'))
Output
C:\home\node>> node hmacUpdate.js Hmac is: 641538b74bf1a59cd9a5cbd97dd0cf3b76b572e17432997230ae346feb41d149
Example 2
// Hmac.digest() Demo Example // Importing the crypto module const crypto = require("crypto") // Initializing the Hmac object with encoding and key const hmac = crypto.createHmac('sha256', 'secretKey'); const hmac1 = crypto.createHmac('sha256', 'secretKey'); const hmac2 = crypto.createHmac('sha256', 'secretKey'); // Updating hmac with below data hmac.update('TutorialsPoint'); hmac1.update('TutorialsPoint'); hmac2.update('TutorialsPoint'); // Printing the hmac value using different digests console.log("Hmac(with hex Encoidng) is: " + hmac.digest('hex')) console.log("Hmac(with Base64 Encoding) is: " + hmac1.digest('base64')) console.log("Hmac(with Default Encoding) is: " + hmac2.digest())
Output
C:\home\node>> node hmacUpdate.js Hmac(with hex Encoidng) is: 9534f1298c89fcd4e42e3fecbb26ac66148a1a607e6fb122ef0af4859f9eb0e5 Hmac(with Base64 Encoding) is: lTTxKYyJ/NTkLj/suyasZhSKGmB+b7Ei7wr0hZ+esOU= Hmac(with Default Encoding) is: �4�)�����.?�&�f��`~o�"���
- Related Questions & Answers
- What is HMAC in Information Security?
- Golang Program to update the node value after the Kth node.
- How to use jQuery.getScript() method to load external js files?
- How to include multiple js files using jQuery $.getScript() method?
- How to update the specific node of the XML file using PowerShell?
- Golang Program to update the first node value in a linked list.
- Golang Program to update the last node value in a linked list.
- Golang Program to update the node value after the Kth node (When K is not in the linked list).
- XHTML and D3.js
- HTML5 / JS storage event handler
- SVG morphing in React JS
- Golang Program to update the ith index node value, when index is at 0 index.
- JS Geolocation but without prompting possible?
- Why do I need Babel JS?
- Adding Lottie animation in React JS
- SVG drawing in React JS frontend
Advertisements