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的区别

计算字符串长度

复制代码
${#字符串变量}
相关推荐
Mac技巧大咖4 小时前
macOS 27 或成 Intel Mac 分水岭:老款 Mac 用户升级前要注意什么?
macos·macos 27
上天_去_做颗惺星 EVE_BLUE6 小时前
【新 Linux 服务器上手全攻略】系统巡检、存储规划与开发环境初始化
linux·运维·服务器·ubuntu·macos·centos
REDcker6 小时前
WWDC2026系统更新综述
macos·ios·开发者·apple·wwdc·ipados·wwdc2026
Sammyyyyy8 小时前
2026 Mac 本地大模型部署深度解析与混合架构指南
数据库·人工智能·macos·ai·架构·servbay
亚林瓜子8 小时前
mac自动启动位置
macos
zahuilg108 小时前
Mac原生终端SSH一键快捷连接|无需装软件、极简安装、快速上手
macos·ssh·github·终端
2501_9159214310 小时前
uni-app 上架 iOS 的完整流程(无需依赖 Mac)
android·macos·ios·小程序·uni-app·iphone·webview
mpr0xy10 小时前
行走编程:把你的 Mac 变成一台随身 AI 开发工作站
人工智能·macos·ai·大语言模型·ai编程·ai写需求
Fatbobman(东坡肘子)10 小时前
WWDC 2026 初印象:符合预期,但更务实 -- 肘子的 Swift 周报 #139
人工智能·macos·ios·swiftui·swift·wwdc
前端 贾公子10 小时前
使用 wxappUnpacker 工具进行 MAC 微信小程序反编译
macos·微信小程序·小程序