简体   繁体   English

Linux 中的散列命令之间的区别

[英]Difference between hashing commands in Linux

I am trying to get passwords hashes encoded in base64 for a login database.我正在尝试获取在 base64 中编码的密码哈希以用于登录数据库。 I am using the picketbox security library to get the base64 encoded hashes of the passwords, but I would like to get a different tool.我正在使用 Picketbox 安全库来获取 base64 编码的密码哈希,但我想获得一个不同的工具。

  1. If I use:如果我使用:

     java -cp $JBOSS_HOME/modules/system/layers/base/org/picketbox/main/picketbox-4.9.6.Final.jar org.jboss.security.Base64Encoder master SHA-256

    I get:我得到:

     [/GE7Tf1nNqe9JoyKDnTtDRwEqVn1nddO8odJg/1EP8k=];

    [ ] must be removed in database to log in properly. [ ]必须在数据库中删除才能正确登录。

  2. When I use:当我使用:

     echo -n master | openssl dgst -sha256 -binary | base64

    I get:我得到:

     /GE7Tf1nNqe9JoyKDnTtDRwEqVn1nddO8odJg/1EP8k=

The same result.同样的结果。

  1. However when I use:但是,当我使用:

     echo -n master |sha256sum -b | base64

    I get:我得到:

     ZmM2MTNiNGRmZDY3MzZhN2JkMjY4YzhhMGU3NGVkMGQxYzA0YTk1OWY1OWRkNzRlZjI4NzQ5ODNmZDQ0M2ZjOSAqLQo=

What is the difference between openssl dgst -sha256 -binary and sha256sum -b ? openssl dgst -sha256 -binarysha256sum -b有什么区别? I thought they would provide the same hash.我以为他们会提供相同的 hash。

Take a look at the difference between openssl and sha256sum :看看opensslsha256sum的区别:

  • openssl prints the hash in raw binary. openssl以原始二进制格式打印 hash。 It's not text, it's not human readable, it's pure bytes:它不是文本,不是人类可读的,它是纯字节:

     $ echo -n master | openssl dgst -sha256 -binary �Y��N�I��D?�

    If you count the bytes with wc ---bytes you'll see it's printing exactly 32 bytes:如果你用wc ---bytes来计算字节数,你会看到它正好打印了 32 个字节:

     $ echo -n master | openssl dgst -sha256 -binary | wc --bytes 32

    We can also convert it to hex with hexdump :我们还可以使用hexdump将其转换为十六进制:

     $ echo -n master | openssl dgst -sha256 -binary | hexdump 0000000 61fc 4d3b 67fd a736 26bd 8a8c 740e 0ded 0000010 041c 59a9 9df5 4ed7 87f2 8349 44fd c93f 0000020
  • By contrast, sha256sum prints the hash in human readable form in hexadecimal using the digits 0-9 and the letters af .相比之下, sha256sum使用数字0-9和字母af以十六进制格式以人类可读的形式打印 hash。

     $ echo -n master | sha256sum -b fc613b4dfd6736a7bd268c8a0e74ed0d1c04a959f59dd74ef2874983fd443fc9 *-

    It's the same information as the garbled binary above but it's presented differently.它与上面的乱码二进制信息相同,但呈现方式不同。 You'll notice that the hex value takes up a lot more space than the binary data.您会注意到十六进制值比二进制数据占用更多空间。 It also includes the file name at the end, which here is the cryptic *- .它还包括最后的文件名,这里是神秘的*- * means you used the -b flag, while - denotes that the input was read from stdin. *表示您使用了-b标志,而-表示输入是从标准输入读取的。

You can get the same hex value from openssl if you change -binary to -hex :如果将-binary更改为-hex ,则可以从openssl获得相同的十六进制值:

$ echo -n master | openssl dgst -sha256 -hex
(stdin)= fc613b4dfd6736a7bd268c8a0e74ed0d1c04a959f59dd74ef2874983fd443fc9

There's no way to do the reverse, though.但是,没有办法做相反的事情。 sha256sum doesn't have a flag to print a binary hash. sha256sum没有用于打印二进制 hash 的标志。 It can only do hex.它只能做十六进制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM