mac命令行下计算文件SHA-256散列值

源起

从国内的第三方网站下载了Android sutiod的zip包下载地址,为了安全起见还是得跟Android官网上的对应的zip包的SHA值做下对比。以前是经常使用md5命令的,所以理论在命令行下应该是有对应的命令行工具可以计算SHA值的。后来搜索到可以用 shasum命令来完成我的需求。

我们man一下shasum命令,注:需要注意-a参数,即计算文件散列值时可以选择具体的算法

复制代码
SHASUM(1)                                                     Perl Programmers Reference Guide                                                     SHASUM(1)


NAME
       shasum - Print or Check SHA Checksums

SYNOPSIS
        Usage: shasum [OPTION]... [FILE]...
        Print or check SHA checksums.
        With no FILE, or when FILE is -, read standard input.

          -a, --algorithm   1 (default), 224, 256, 384, 512, 512224, 512256
          -b, --binary      read in binary mode
          -c, --check       read SHA sums from the FILEs and check them
              --tag         create a BSD-style checksum
          -t, --text        read in text mode (default)
          -U, --UNIVERSAL   read in Universal Newlines mode
                                produces same digest on Windows/Unix/Mac
          -0, --01          read in BITS mode
                                ASCII '0' interpreted as 0-bit,
                                ASCII '1' interpreted as 1-bit,
                                all other characters ignored

        The following five options are useful only when verifying checksums:
              --ignore-missing  don't fail or report status for missing files
          -q, --quiet           don't print OK for each successfully verified file
          -s, --status          don't output anything, status code shows success
              --strict          exit non-zero for improperly formatted checksum lines
          -w, --warn            warn about improperly formatted checksum lines

          -h, --help        display this help and exit
          -v, --version     output version information and exit

        When verifying SHA-512/224 or SHA-512/256 checksums, indicate the
        algorithm explicitly using the -a option, e.g.

实践


PS: sha256算法的散列值是256个byte,即256/8=32字节,1个字节用2位16制表示,即散列值的长度为64个字符

对比一下官网的信息,good,安全较验通过!

回顾

md5与sha256的区别

计算字符串长度

复制代码
${#字符串变量}
相关推荐
海的辽阔4 小时前
如何在MAC下安装EcomGpt模型
macos·大模型·ecomgpt
zandy10114 小时前
hermes agent 安装教程 3.0:Win / Mac / Linux 全平台指南
linux·运维·macos
花开·莫之弃5 小时前
Mac安装多版本jdk(jenv)
java·开发语言·macos
June bug9 小时前
(Mac)torch==2.1.2 与 Python 3.12 不兼容+onnxruntime-silicon 不支持 Intel Mac
开发语言·python·macos
码农小北9 小时前
MAC 配置鸿蒙(HarmonyOS) SDK 环境变量完整指南
macos·华为·harmonyos
June bug9 小时前
Intel Mac 搭建AI后端项目环境 三次报错问题汇总+完整解决方案
人工智能·macos
viperrrrrrrrrr79 小时前
语音AI的2026:从“听见声音“到“理解世界“
人工智能·macos·语言模型
初願致夕霞10 小时前
Linux网络编程_数据链路层MAC帧协议与ARP协议
linux·网络·网络协议·macos
app开发工程师V帅10 小时前
Xcode 工程内引入工程、framework内引入framework、OC的framework引入swift 的framework等等
ide·macos·xcode
薛定猫AI13 小时前
Codex 与 Claude Code 全平台安装配置指南(Windows / macOS / Linux)
linux·windows·macos