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

计算字符串长度

复制代码
${#字符串变量}
相关推荐
阿赛工作室3 小时前
mac系统使用Hbuilderx调试安装app
macos
weixin_462446238 小时前
Linux/Mac 一键自动配置 JAVA_HOME 环境变量(含 JDK 完整性校验)
java·linux·macos
Frank学习路上8 小时前
【Qt】问题记录ld: framework ‘AGL‘ not found on MacOS 26
开发语言·qt·macos
SoraLuna8 小时前
KuiklyUI for OpenHarmony 实战 02:Kuikly 工程创建与鸿蒙运行(Mac)
macos·华为·harmonyos
微信-since811929 小时前
【mac】 mac使用
macos
REDcker1 天前
macOS「系统数据」暴涨到 几百GB?一篇文章教你安全清理(含排查顺序)
macos
sysinside1 天前
macOS Sequoia 15.7.2 (24G325) 正式版 ISO、IPSW、PKG 下载
macos·sequoia
只是有点小怂1 天前
macOS 没有像 Windows 上的 MobaXterm 的工具
macos
小雨青年1 天前
环境准备 Windows Mac 下 Docker Desktop 的安装与镜像源加速
windows·macos·docker
数据知道1 天前
一文掌握 MongoDB 详细安装与配置(Windows / Linux / macOS 全平台)
linux·数据库·windows·mongodb·macos