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

计算字符串长度

复制代码
${#字符串变量}
相关推荐
明似水40 分钟前
macOS 更新后找不到钥匙串访问工具的解决方案
macos
一牛5 小时前
Appkit: 菜单是如何工作的
macos·ios·objective-c
tkevinjd6 小时前
文件操作、流对象示例
macos·objective-c·cocoa
Dachui_11221 天前
MacOS上如何运行内网穿透详细教程
macos
Bruce_Liuxiaowei1 天前
使用Python脚本在Mac上彻底清除Chrome浏览历史:开发实战与隐私保护指南
chrome·python·macos
iFlyCai1 天前
对Mac文字双击或三击鼠标左键没有任何反应
macos·计算机外设
請你喝杯Java2 天前
Mac上Cursor无法安装插件解决方法
macos·cursor·vsode
网络之路Blog2 天前
【实战中提升自己】内网安全部署之端口隔离与MAC地址认证
安全·macos·网络之路一天·华为华三数通基础·华为华三企业实战架构·华为中小型企业实战·华为华三计算机网络基础
心随_风动2 天前
主流操作系统对比分析(macOS、Linux、Windows、Unix)
linux·windows·macos
lxw18449125142 天前
macOS 系统设置息屏情况下,PHP等后台脚本继续执行
macos