首页 文章

openssl sha256 diff

提问于
浏览
2

我使用的是openssl 1.0.1c,linux x86_64

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

  • openssl dgst -sha256 hello_file

我得到:5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03


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

我得到:2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824

最令人困惑的部分是,如果我正在尝试使用 "hello(new line character)" 在线计算器

1返回:5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03

这正是我用openssl得到的 . 所有其他人都回来了

2,3,4,5:cd2eca3535741f27a8ae40c31b0c41d4057a7a7b912b33b9aed86485d1c84676

我知道有关echo的新行问题,但我不知道每个文件都附加了新行 . So how can i get sha256 of file without new line character ? 所有其他计算器出了什么问题?

提前致谢

基里尔


3 convertedtring.com/Hash/SHA256

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

5 quickhash.com

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..
    

相关问题