hbruce
hbruce

Reputation: 932

How to get file crc/checksum in asp.net

Given a file on the local filesystem:

FileInfo file = new FileInfo(localFilename);

How can I get a CRC-value (or some kind of checksum) for that file?

Upvotes: 3

Views: 4430

Answers (1)

Stephen Cleary
Stephen Cleary

Reputation: 457167

Hash algorithms are generally better than CRCs because they have fewer collisions; modern hash algorithms are implemented as descendents of the HashAlgorithm class. MD5 and SHA1 are common choices.

AFAIK, .NET does not include CRC classes, but I've written CRC32 and CRC16 classes that support all CRC-32 and CRC-16 algorithms.

To calculate the checksum (whether a hash algorithm or CRC), you'll have to read in the entire file, chunk by chunk, passing the file data to the checksum algorithm. When you're done with the entire file, retrieve the result from the checksum algorithm.

Upvotes: 5

Related Questions