文件一致性校验(MD5,SHA1,GPG)


一 为何要进行文件一致性校验?

为了确保你得到的文件是正确的版本,而没有被注入病毒和木马程序。例如我们经常在网上下载软件,而这些软件已经被注入了一些广告和病毒等,如果不进行文件与原始发布商的一致性校验的话,可能会给我们带来一定的损失。

二 文件一致性校验原理
要进行文件的一致性校验,我们不可能像文本文件比较那样,将两个文件放到一起对比,因为很多的时候文件很大。目前最理想的办法就是,是通过加密算法,对文件生成对应的值,通过生成的值与发布商提供的值比较来确认两个文件是否一致。

MD5和SHA1就是目前使用最为广泛的良种加密算法。这两种算法都是基于MD4,但又略有不同。一般来说,SHA1计算速度比较慢,但抗穷举行能也更好。

另外,SHA1是美国国家标准局颁布的标准加密算法。因此,在微软发布的Windows操作系统等光盘中,提供的就是sha1校验码。Google Code社区使用也是sha1验证码。

比较常用的还有GPG。

三 文件一致性校验工具

1) MD5+SHA1

* SUM, LINUX命令,用来获得文件的checksum和blocksize,常被用来检测文件是否被修改过。

* cksum, a Unix command that generates both a 32-bit CRC and a byte count for any given input file.
* md5sum, a Unix command that generates a MD5 sum (commonly used to verify .iso files)
* jdigest, a Java GUI tool that generates and checks MD5 and SHA sums
* Unix programs called md5/sha1 or md5sum/sha1sum are included in many unix distributions.
* sum is also available as part of GNU Textutils.
* md5, a command line utility usable on either Unix or MS-DOS/Windows, which generates and verifies message digests (digital signatures) using the MD5 algorithm. This program can be useful when developing shell scripts or Perl programs for software installation, file comparison, and detection of file corruption and tampering.
* 还有fsum
* HashCalc /super hash calc 一个超强的文件校验码计算工具!速度快,支持算法多,直接拖动即可计算,十分方便!还可对字串直接计算!

2) PGP
* The PGP signatures can be verified using PGP or GPG. First download the KEYS as well as the asc signature file for the particular distribution. Make sure you get these files from the main distribution directory, rather than from a mirror. Then verify the signatures using
% pgpk -a KEYS
% pgpv apache-ant-1.7.1-bin.tar.gz.asc
or
% pgp -ka KEYS
% pgp apache-ant-1.7.1-bin.tar.gz.asc
or
% gpg --import KEYS
% gpg --verify apache-ant-1.7.1-bin.tar.gz.asc

A command line version of GnuPG is also available for Windows users.

 

四 参考:

http://ant.apache.org/bindownload.cgi

http://www.fastsum.com/

http://fsumfe.sourceforge.net/

http://www.slavasoft.com/fsum

 

五 MD5创建和验证

1) 创建MD5验证码(fsum)

2)验证 (super hash calc)

 

 完!

posted @   iTech  阅读(11353)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
点击右上角即可分享
微信分享提示