在 Git Bash 终端中验证文件的 sha256 哈希值的最简单方法如下:
# Go to the directory in which the downloaded file exists
cd /path/to/directory/
# Validate sha256 hash of the file
sha256sum name_of_the_file
Run Code Online (Sandbox Code Playgroud)
这将在终端中打印文件的 sha256 哈希值,然后您可以将其与下载文件的网站中存在的原始哈希值进行比较。
例如,您可以从此处下载任何 PHP 版本:php.net/download并验证其 sha256 哈希值,如上所述。
另一种验证方法是这样的:
echo "the_original_sha256sum_of_the_file the_name_of_the_file" | sha256sum -c
Run Code Online (Sandbox Code Playgroud)
例子:
echo "2a1468ab5dd540beb161d7b388ed2d80e2515ab112244b08ac201f5bf846d052 php-7.3.23-Win32-VC15-x64.zip" | sha256sum -c
Run Code Online (Sandbox Code Playgroud)
如果文件的 sha256 哈希值有效,则下一行(包含文件名后跟单词 OK)将在终端中打印:
php-7.3.23-Win32-VC15-x64.zip: OK
Run Code Online (Sandbox Code Playgroud)
如果您有 sha256sum 文件,您可以像这样验证下载的文件:
sha256sum -c name_of_the_sha256sum_file
Run Code Online (Sandbox Code Playgroud)
例如,如果您下载了这些phpMyAdmin 版本的任何版本及其 sha256 文件,那么您可以根据上述方法验证该文件,如下所示:
sha256sum -c phpMyAdmin-5.0.2-english.zip.sha256
Run Code Online (Sandbox Code Playgroud)
这将打印下一行,这意味着该文件有效:
phpMyAdmin-5.0.2-english.zip: OK
Run Code Online (Sandbox Code Playgroud)
注意,你可以根据自己的需要来使用sha1sum而不是使用。sha256sum