Generate and Verify BLAKE2 Hash of File on Linux

Generate and Verify BLAKE2 Hash of File on Linux

BLAKE2 is a cryptographic hash function commonly used to confirm file integrity. It helps detect whether a file has been modified after storage or transfer. This tutorial explains how to generate and verify BLAKE2 hash of file on Linux.

Generate BLAKE2 hash

Create a sample file for testing:

printf 'Hello world' > test.txt

Use the b2sum command to calculate the BLAKE2 hash of the file:

b2sum test.txt

Output:

6ff843ba685842aa82031d3f53c48b66326df7639a63d128974c5c14f31a0f33343a8c65551134ed1ae0f2b0dd2bb495dc81039e3eeb0aa1bb0388bbeac29183  test.txt

The hash can also be saved into a separate file:

b2sum test.txt > test.b2

Verify BLAKE2 hash

To verify file integrity, use -c option as follows:

b2sum -c test.b2

Output:

test.txt: OK

Modify the file by appending additional content:

printf 'Hi' >> test.txt

Run the verification command again to check integrity:

test.txt: FAILED
b2sum: WARNING: 1 computed checksum did NOT match

Leave a Comment

Cancel reply

Your email address will not be published.