How to use SHA-256 with Node.js crypto? - The Web Dev (2024)

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

How to use SHA-256 with Node.js crypto? - The Web Dev (1)

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 use SHA-256 with Node.js crypto? - The Web Dev (2)

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

View Archive

How to use SHA-256 with Node.js crypto? - The Web Dev (2024)
Top Articles
Latest Posts
Article information

Author: Otha Schamberger

Last Updated:

Views: 6465

Rating: 4.4 / 5 (75 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Otha Schamberger

Birthday: 1999-08-15

Address: Suite 490 606 Hammes Ferry, Carterhaven, IL 62290

Phone: +8557035444877

Job: Forward IT Agent

Hobby: Fishing, Flying, Jewelry making, Digital arts, Sand art, Parkour, tabletop games

Introduction: My name is Otha Schamberger, I am a vast, good, healthy, cheerful, energetic, gorgeous, magnificent person who loves writing and wants to share my knowledge and understanding with you.