In the previous exercise you created a simple file-downloader that automatically discoveres servers to download the file from. But it has a serious security problem: What if a peer (the server in this exercise) is a bad actor and wants to send you malicious data?
This exercise introduces you to a concept called hashing that we can later use to validate that the data we're getting has not been compromised.
Hashing is essentially a way to create a small fingerprint representing a large chunk of data. Many different hashing algorithms exists, but in this workshop we'll just use one called sha256
.
Write a program that prints out the sha256
hash of the string 'Web Rebels 2017'.
When working with hashing in Node.js, we use the crypto module from Node core. Use the method createHash()
.
var crypto = require('crypto')
var hash = crypto.createHash('sha256')
//...
Hash the string Web Rebels 2017
and verify that the hex value of the hash is a25cc4405386d2abaf835b8f57710de683cb99f6e7833c4cd59b6d57f0171877
When you are done click here to go to the next exercise