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?
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.
精彩评论