Local hash doesn't match CyberChef? echo newline & MD5 fix
Terminal hash differs from CyberChef? Two usual causes: echo adds a newline, and MD5 hex text is not raw bytes. Exact commands to make both sides match.
GuideUpdated 6 min read
On this page
You ran a hash in Terminal, ran the "same" recipe in CyberChef, and got different results. A typical report: MD5, then Base64, then SHA-1 gave 806825f0... in CyberChef and 069eba37... in the terminal. The replies on that cryptography forum thread named two causes: echo puts a newline at the end, and CyberChef's MD5 outputs the hex digest, not binary like openssl -binary. We can't see the original input, but both causes are common and they can stack.
Why the hashes differ
Most common first:
- The newline from
echo.echo hellowrites the five letters plus a line break, so the hash tool receives 6 bytes instead of 5. - Hex text versus raw bytes between stages. An MD5 digest is 16 bytes. You can hand it to the next step as 32 hex characters or as the 16 bytes themselves. Everything downstream differs.
- Newlines reintroduced later. Command substitution,
echo "$var", andopenssl base64without-Acan add or wrap line breaks at any stage. - Smaller mismatches. Windows line endings, a different text encoding, URL-safe Base64, or a different step order.
Neither side is "wrong". Each hashed exactly what it received. The job is to make both receive the same bytes at every stage.
Fix 1: stop echo from adding a newline
| Command | What gets hashed | MD5 |
|---|---|---|
echo hello | md5 -q | hello + newline (6 bytes) | b1946ac92492d2347c6235b4d2611184 |
echo -n hello | md5 -q | hello (5 bytes) | 5d41402abc4b2a76b9719d911017c592 |
printf '%s' hello | md5 -q | hello (5 bytes) | 5d41402abc4b2a76b9719d911017c592 |
The last two rows are the MD5 of the five characters hello, which any tool hashing exactly that input should print. Use this form:
printf '%s' 'hello' | md5 -qmd5 is the macOS built-in command and -q prints only the hash. It changes nothing on your system, so there is nothing to undo.
We prefer printf '%s' to echo -n. The -n flag behaves differently across shells, while printf '%s' is consistent.
Fix 2: hash the same representation on both sides
If the next step after MD5 is Base64, Base64 encodes whatever bytes it receives. The lengths tell you which one went in:
| What goes into Base64 | Output length | Example for hello |
|---|---|---|
| 16 raw bytes | 24 characters | XUFAKrxLKna5cZ2REBfFkg== |
| 32 characters of hex text | 44 characters | starts with NWQ0MTQw |
Terminal: hash the hex text
printf '%s' 'hello' | md5 -q | tr -d '\n' | openssl base64 -A | tr -d '\n' | shasum -a 1This takes the MD5 hex text, Base64-encodes that text, and takes the SHA-1 of the Base64 string. shasum prints the hash followed by -; ignore the dash. People on the forum report that this is what CyberChef's MD5 step hands over, so this is the variant to try first when matching a CyberChef recipe.
Terminal: hash the raw bytes
printf '%s' 'hello' | openssl dgst -md5 -binary | openssl base64 -A | tr -d '\n' | shasum -a 1This Base64-encodes the 16 raw digest bytes, then takes the SHA-1 of that string. A CyberChef recipe matches it only if the bytes, not the hex text, flow from MD5 into the Base64 step. Look at how your recipe's steps hand over their output, and check each stage's output before trusting the final one.
Compare stage by stage
When a chain disagrees, stop guessing and compare every stage on both sides.
- Compare the input length.
printf '%s' 'hello' | wc -cprints 5. With a newline it is 6. - Compare the first hash as hex. For MD5 it should be 32 characters. If it differs, the input differs (usually a newline, a stray space, or different line endings).
- Compare the Base64 string. 24 characters ending in
==means raw bytes went in. 44 characters means hex text went in. - Compare the final hash only after the earlier stages agree.
To see a binary stage as readable hex in the terminal:
printf '%s' 'hello' | openssl dgst -md5 -binary | xxd -pThis prints the raw digest bytes as hex, so you can compare them with the other side's hex output. It changes nothing.
Checklist before you try again
- Input has no trailing newline (5 bytes for
hello, not 6). - Both sides use the same text encoding (UTF-8 is the usual choice).
- You know whether each hand-off is hex text or raw bytes.
- Base64 is on one line (
-A) and uses the same alphabet on both sides. - You copied only the hex from
shasumoropenssl dgst, not labels or the trailing-. - Steps run in the same order: MD5, then Base64, then SHA-1 is not Base64, then MD5.
Other things that break a match
- Windows line endings. Text copied from a Windows file may end in
\r\n, which is 2 extra bytes. Strip them, or hash the file's actual bytes. - Non-ASCII text. Both sides must use the same encoding, or the bytes differ even when the text looks identical.
- URL-safe Base64. If one side uses
-and_with no=padding, the strings differ even for the same bytes. - Wrapped Base64.
openssl base64without-Awraps long output across lines. Use-Aandtr -d '\n'before hashing.
Checking the text stages in Bytepliers
The terminal commands above are what fix this problem. Bytepliers helps with one part: seeing each text stage. Its Hash Generator hashes the text in the input pane (shown as UTF-8), so what you see is what gets hashed. Open Hash Generator (⌘5), stay on the Text tab, paste your input, pick MD5, and delete any trailing line break first. The Output menu offers hex or Base64, and the Expected checksum field tells you match or mismatch for a digest you already have.
It does not do the raw-bytes variant: its tools and recipes work on text, so use the openssl command for that. If you install its optional command-line tool, --raw keeps a trailing newline from stdin or a file, so by default that newline is dropped. That means echo hello | bytepliers hash -a md5 can differ from echo hello | md5. See the command-line docs.
If nothing works
Contact whoever owns the other side of the comparison: the API vendor whose spec defines the expected value, or the maintainers of the tool you are checking against. Send the exact input, the exact bytes (hex), each stage's output from both sides, and which commands you already tried.
Hi, I'm trying to reproduce the value from your docs and my hash differs.
Input (hex bytes, no trailing newline): 68656c6c6f
Chain: MD5 -> Base64 -> SHA-1
My stage outputs:
MD5 hex: 5d41402abc4b2a76b9719d911017c592
Base64: (24 chars from raw bytes / 44 chars from hex text)
SHA-1: (final hash)
Commands used: printf '%s' 'hello' | openssl dgst -md5 -binary | openssl base64 -A | shasum -a 1
Does your spec pass MD5 as hex text or as raw bytes into the next step,
and is the input hashed with or without a trailing newline?Common questions
Which result is correct, the terminal's or CyberChef's?
Both are correct for what they hashed. The right one is whichever matches the system you're integrating with.
Does the newline problem affect SHA-256 and other algorithms?
Yes. Any hash of hello\n differs from the hash of hello. For file checksums, see how to check a SHA-256 checksum on Mac.
How do I Base64-encode text on a Mac without the trailing newline?
Use printf '%s' 'text' | openssl base64 -A. More methods are in how to encode and decode Base64 on Mac.
Why is my Base64 string 44 characters instead of 24?
You encoded the 32 characters of hex text, not the 16 raw digest bytes. Switch to openssl dgst -md5 -binary if you need the 24-character form.