We use cookies to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners. See details
Categories
- Post authorBy John Au-Yeung
- Post dateMarch 5, 2022
- No Comments on How to use SHA-256 with Node.js crypto?
Spread the love
Sometimes, we want to use SHA-256 with Node.js crypto.
In this article, we’ll look at how to use SHA-256 with Node.js crypto.
How to use SHA-256 with Node.js crypto?
To use SHA-256 with Node.js crypto, we call the createHash
method.
For instance, we write
const hash = crypto.createHash('sha256').update(pwd).digest('base64');
to call createHash
with 'sha256'
and call update
with the string we want to creatre the has from to create the hash.
Then we return the hash digest string from the hash with the digest
method.
We pass in 'base64'
as the argument, so the base64 hash digest is returned.
Also, we can pass in 'hex'
to digest
to return a hex hash digest.
Conclusion
To use SHA-256 with Node.js crypto, we call the createHash
method.
Related Posts
How to debug Node.js applications?
Sometimes, we want to debug Node.js applications. In this article, we'll look at how to…
How to exit a Node.js program?
Sometimes, we want to exit a Node.js program. In this article, we'll look at how…
How to enable HTTPS on Express.js and Node.js?
Sometimes, we want to enable HTTPS on Express.js and Node.js. In this article, we'll look…
By John Au-Yeung
Web developer specializing in React, Vue, and front end development.