Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SHA256 output does not match one generated on Linux terminal #60

Open
andriusign opened this issue Feb 13, 2025 · 6 comments
Open

SHA256 output does not match one generated on Linux terminal #60

andriusign opened this issue Feb 13, 2025 · 6 comments

Comments

@andriusign
Copy link

Steps to reproduce:

  1. Generate sha256sum of the string "Example string" using online tool.
  2. Generate sha256sum of the same string "Example string" using Linux terminal with any of the three ways provided in the example.
  3. Compare results.

Actual: hashes do not match
Expected: hashes should match

Visual proof:
Image

Tested on:
OS: Linux Mint 21.3 Cinnamon 6.0.4
Kernel: 6.8.0-51-generic
Gnome terminal, Version 3.44.0 for GNOME 42
Browser: Chromium Version 131.0.6778.204 (Official Build) for Linux Mint (64-bit)

@JonnyTech
Copy link

echo appends a new line to the string, and I suspect that your files contains it too, so you are comparing different strings to the tool, therefore try echo -n or printf or paste the file here

@andriusign
Copy link
Author

andriusign commented Feb 13, 2025

But If you check I am NOT using echo in other 2 commands (cat and sha256sum < text) and the file does not contain a new line. What could cause this?

@JonnyTech
Copy link

The hash created from the file and the echo command are identical so I conclude it does contain a new line character until you provide proof.

Please paste the output from:

xxd text

and

hexdump -C text

Where text is the name of the file.

@andriusign
Copy link
Author

andriusign commented Feb 13, 2025

:~/Desktop$ xxd text 
00000000: 4578 616d 706c 6520 7374 7269 6e67 0a    Example string.

:~/Desktop$ hexdump -C text 
00000000  45 78 61 6d 70 6c 65 20  73 74 72 69 6e 67 0a     |Example string.|
0000000f

You're right, it's a null terminator that is causing this. Using printf matches:

~/Desktop$ printf "Example string" | sha256sum
8e73133b4768e655a86ff65533849a3f72ec0831f74cdffc178ab16582cc1293  -

@JonnyTech
Copy link

FYI the hex character 0A is a "line feed" character not a "null terminator". Glad that we identified the cause, please close this issue.

@emre-tarhan
Copy link

you should use it with the -n flag. the echo command adds a new line so your output will be different, but if you use -n, no new line is added and you get the result you want:

echo 'Example string' | sha256sum

res: 0a33c75cee8ed29eb41a9d242d7ffd4a148e1fc70d365ec91dfcc7c02ae8289c -

echo -n 'Example string' | sha256sum

res 8e73133b4768e655a86ff65533849a3f72ec0831f74cdffc178ab16582cc1293 -

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants