如何在asp.net中获取文件crc/checksum

发布于 2024-09-17 04:56:16 字数 123 浏览 8 评论 0原文

给定本地文件系统上的文件:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云仙小弟 2024-09-24 04:56:16

哈希算法通常比 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文