

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 5
click for more info
Not enough gems
Cost: 6 gems
1: What Is a Message Integrity?
incomplete
2: Message Authentication Code (MAC)
incomplete
3: Message Authentication Code (MAC)
incomplete
4: Hash-Based Message Authentication Code
incomplete
5: Toy HMAC
incomplete
6: MACs and JWTs
incomplete
7: Asymmetric JWTs
incomplete
8: Asymmetric JWT Review
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Message integrity ensures that a message has not been changed.
Let's say you need to transmit a private key from your computer to your phone. Because your network connection isn't great, there's a chance that information is lost in transit. You want to be sure that the private key makes it to your phone in pristine condition. If there is data loss, you'll want to know about it so you can try again.
To accomplish this, we can take a hash of the private key, and send it alongside the key. When the private key is transmitted, you'll be able to check on your phone by hashing the private key and checking if the hashes match.
This "hash and check" method is called a checksum.
hash(data)(hash(data) == checksum) then the message has not been alteredComplete the checksumMatches function.
Convert the message to a slice of bytes and hash it using sha256. Check if the lowercase hexadecimal encoding of the hash matches the checksum argument. If it does, return true. Otherwise, return false.