Thursday, February 3, 2011

Verifying checksums in linux

Kinds of checksum algorithms - md5, sha1, sha224, sha256 etc.

Given a file abc and a checksum a1b23c using the md5 algorithm, run
md5sum abc | grep "a1b23c"
If the output is "a1b2c3      abc", the check succeeded.
If there is no output, the check failed.

md5sum calculates the checksum for the file abc using the algorithm md5 and prints to console. grep checks if that's the checksum you expected. If the check failed, grep will be silent.

Replace md5sum with sha1sum, sha224sum etc.

Each algorithm uses a certain number of bits for the calculation. The more bits the algorithm uses, the better.

md5 - 128 bits
sha1 - 160 bits
sha224 - 224 bits
sha256 - 256 bits

No comments:

Post a Comment