如何在asp.net中获取文件crc/checksum
给定本地文件系统上的文件:
FileInfo file = new FileInfo(localFilename);
如何获取该文件的 CRC 值(或某种校验和)?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
哈希算法通常比 CRC 更好,因为它们的冲突更少;现代哈希算法是作为
的后代实现的HashAlgorithm
类。 MD5 和 SHA1 是常见的选择。AFAIK,.NET 不包含 CRC 类,但我已经编写了 CRC32 和 CRC16 类支持所有 CRC-32 和 CRC- 16 种算法。
要计算校验和(无论是哈希算法还是 CRC),您必须逐块读取整个文件,并将文件数据传递给校验和算法。完成整个文件后,检索校验和算法的结果。
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.