【问题标题】:How to installing sha1sum in MAC OS?如何在 MAC OS 中安装 sha1sum?
【发布时间】:2015-04-13 22:59:18
【问题描述】:

问题: 要在 MAC OS 中获取文件的 sha1sum 值,我运行以下命令

sha1sum file_name

我得到的错误如下

perl version 5.18.2 can't run /usr/bin/sha1sum.  Try the alternative(s):

/usr/bin/sha1sum5.16 (uses perl 5.16)

Run "man perl" for more information about multiple version support in
Mac OS X.

我尝试安装 textutils 和 coreutils,但都失败了。谁能建议我如何解决这个问题?提前致谢。

【问题讨论】:

  • 你为什么不把sha1sum别名为/usr/bin/sha1sum5.16
  • 我正在从 python 脚本调用 sha1sum,而不仅仅是试图找到一个特定的文件。
  • 我明白,但这真的有关系吗?我假设您只是在执行 shell 脚本/二进制文件,所以我所说的只是使用符号链接或别名来执行您需要的二进制文件。显然你想要的命令是存在的,只是对于安装的 Perl 和 OS 版本的名称不同。另外,我很难相信 Python 没有获取 sha1 校验和的工具——为什么不使用它来减少外部依赖?
  • 就安装而言,您是否尝试使用 Macports 或 Homebrew?
  • 我宁愿直接在 Python 代码中进行散列,而不是调用外部程序。它的代码多一点,但可能更有效。它还使您摆脱了外部依赖。见pythoncentral.io/hashing-files-with-python

标签: macos sha1


【解决方案1】:

您可以使用带有brew install md5sha1sum 的自制软件在Mac OS 中安装它。从此链接获取信息https://raamdev.com/2008/howto-install-md5sum-sha1sum-on-mac-os-x/

【讨论】:

  • 我发现我的用例的功能与本机 shasum 命令没有区别。例如,echo -n "test" | shasum 的输出与echo -n "test" | sha1sum 的输出相同。
【解决方案2】:

MacOS 预装了shasum,默认计算sha1 sum:

$ shasum --help
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
[...]

使用示例:

$ echo -n "test" | shasum
a94a8fe5ccb19ba61c4c0873d391e987982fbbd3  -

openssl sha1 也可以完成这项工作:

$ echo -n "test" | openssl sha1
a94a8fe5ccb19ba61c4c0873d391e987982fbbd3

【讨论】:

  • 它们都是空字符串的哈希,因为您的命令有错误。正确的使用方法是回显字符串``` echo -n "test" | openssl sha1 或 echo -n "test" |沙萨姆```
  • @itmard 你是对的!我已经更新了答案,谢谢!
【解决方案3】:

可以使用shasum或者openssl计算hash

echo -n "yourpassword" | openssl sha1
b48cf0140bea12734db05ebcdb012f1d265bed84


echo -n "yourpassword" | shasum
b48cf0140bea12734db05ebcdb012f1d265bed84

【讨论】:

    猜你喜欢
    • 2014-05-29
    • 1970-01-01
    • 2020-12-14
    • 1970-01-01
    • 2021-12-14
    • 2020-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多