2

我正在使用 openssl 1.0.1c , linux x86_64

我正在创建包含“hello”的文件(没有换行符)

  • openssl dgst -sha256 hello_file

我得到:5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03


如果我使用任何其他在线计算(12、 3 、 4 、 5 (因为缺乏声誉我不能做更多的超链接)

我得到:2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824

最令人困惑的部分是,如果我正在尝试使用“hello(换行符)”的在线计算器, 那么

1 返回:5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03

这正是我使用 openssl 得到的。当所有其他人返回时

2、3、4、5 :cd2eca3535741f27a8ae40c31b0c41d4057a7a7b912b33b9aed86485d1c84676

我知道 echo 的新行问题,但我不知道每个文件都附加了新行。那么如何在没有换行符的情况下获得文件的 sha256 呢?所有其他计算器有什么问题?

提前致谢

基里尔


3 convertstring.com/Hash/SHA256

4 webutils.pl/index.php?idx=sha1

5 quickhash.com

4

1 回答 1

3

你是对的,你hello_file有一个换行符:

$ echo 'hello' > hello_file; openssl sha256 hello_file; xxd hello_file
SHA256(hello_file)= 5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03
0000000: 6865 6c6c 6f0a                           hello.

删除新行将取决于您的编辑器,如果您的情况与我发现这篇文章时的情况相似,弄乱密码的哈希值,您可以执行以下操作:

$ echo -n 'hello' > hello_file; openssl sha256 hello_file; xxd hello_file
SHA256(hello_file)= 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
0000000: 6865 6c6c 6f                             hello

您可以执行以下操作来删除最后一个字符(或两个):

$ echo "hello" > hello_file; od -c hello_file; truncate hello_file --size=-1; od -c hello_file
0000000   h   e   l   l   o  \n
0000006
0000000   h   e   l   l   o
0000005

看起来好像其他计算器正在附加一个 dos 样式回车 + 新行

$ echo -en 'hello\r\n' > hello_file; openssl sha256 hello_file; xxd hello_file
SHA256(hello_file)= cd2eca3535741f27a8ae40c31b0c41d4057a7a7b912b33b9aed86485d1c84676
0000000: 6865 6c6c 6f0d 0a                        hello..
于 2013-07-10T18:25:55.847 回答