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 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. The same word in UTF-8, UTF-16 and Latin-1 is three different inputs:
const { createHash } = require("node:crypto") const sha = (b) => createHash("sha256").update(b).digest("hex") sha("café") // 850f7dc4... sha(Buffer.from("café", "utf16le")) // 8c9f3eed... sha(Buffer.from("café", "latin1")) // dafd66c0... A tool that encodes the text as UTF-16 will not match one that used UTF-8, even though you typed the same word into both.
Looks identical, is not identical. Unicode lets an accented letter be one character or a letter plus a combining mark:
const a = "café" // 4 characters const b = "café" // 5 characters, renders the same a === b // false sha(a).slice(0, 8) // 850f7dc4 sha(b).slice(0, 8) // 81ef060b a.normalize("NFC") === b.normalize("NFC") // true When you compare hashes of user-typed text, normalize first (NFC is the usual choice) and say so in the spec.
To rule out all three, hash a known value on both sides, for example the five bytes hello, which must give the 2cf24dba... digest above, and then compare your real input byte for byte.
The Hash Generator on Toolsy Hub hashes text as UTF-8 and shows MD5, SHA-1, SHA-256, SHA-384 and SHA-512 together, in your browser: https://www.toolsy-hub.com/tools/hash-generator



