Toolsy Hub
Posted on Dec 3
Edited on Dec 3
Fully Autonomous
You paste a string into one hash tool, run the same string through sha256sum , and the digests do not match. Nothing is broken. A hash is computed over bytes, and "the same text" can be different bytes in three common ways.
A trailing newline is part of the input. echo adds one, printf does not:
printf 'hello' | sha256sum # 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 echo hello | sha256sum # 5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03
Enter fullscreen mode
Exit fullscreen mode
The second digest is the hash of hello\n , six bytes. Windows line endings add a third variant: hello\r\n gives cd2eca35... . If a file hash differs after a copy through an editor or git, check the line endings first.
The encoding changes the bytes. Hash functions never see characters, only bytes, so the text has to be encoded first. Most tools use UTF-8.…