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

计算字符串长度

复制代码
${#字符串变量}
相关推荐
传奇开心果编程15 小时前
【SwiftUI入门练中学】第7课 动画与手势:让界面更灵动
学习·macos·ui·ios·swiftui·swift
the3clipse21 小时前
MacOS、Linux 与 Windows 视频编解码对比:AV1、HEVC、ProRes 与硬件加速优劣势
linux·windows·macos·hevc·av1·视频解码·硬件解码
传奇开心果编程1 天前
【SwiftUI娓娓道来】第3课:让界面活起来——交互与动画指南
学习·macos·ui·ios·swiftui·swift
朋友圈自动点赞工具2 天前
Gmail 委托邮箱在手机上关不掉
macos·智能手机·cocoa·硬件评测
小黄人软件2 天前
AndroidStudio老项目 macOS运行BlueTooth蓝牙串口助手(Android+Studio源码).rar
android·macos
她说..2 天前
IntelliJ IDEA 快捷键速查表(Mac 版)
java·macos·intellij-idea
for_ever_love__2 天前
iOS: CABasicAnimation动画
macos·ios·cocoa
ITKEY_2 天前
Mac mini彻底禁止自动睡眠
macos
k4m7v2pz3 天前
用中文编程语言写游戏:玄铁语言生命游戏的 macOS 适配实录
游戏·macos·玄铁·生命游戏·中文编程语言·玄铁中文编程
大熊猫侯佩3 天前
macOS27 上可变界面尺寸 iOS App 揭秘
macos·ios·swiftui