Hash generator · Guide
MD5 Hash Base64: Encode a Digest as Base64 Instead of Hex
Most tools print MD5 as 32 hex characters, but several protocols want the same 16 bytes encoded as Base64 instead. The digest is identical — only the way those bytes are written changes.
Hex and Base64 are the same bytes
An MD5 digest is 16 raw bytes. Hex writes each byte as two characters, giving 32. Base64 packs every 3 bytes into 4 characters, giving 24 with padding — shorter, but not readable as pairs.
Converting between them never touches the digest. Decode the hex to bytes, re-encode those bytes as Base64, and you have the other form of the same hash.
Producing it
The key detail is hashing to raw binary rather than hex before encoding:
# shell: -binary is what makes the difference
openssl md5 -binary file.txt | base64
# PHP: the second argument returns raw bytes
base64_encode(md5($data, true));
# Python
import base64, hashlib
base64.b64encode(hashlib.md5(data).digest())A very common bug is Base64-encoding the hex string instead of the digest. That produces 44 characters rather than 24 — if your output is too long, this is why.
Where Base64 MD5 is required
The HTTP Content-MD5 header carries a Base64 digest, as does the equivalent integrity header in Amazon S3 uploads. Some SOAP and EDI integrations specify it too.
Outside those protocols, prefer hex — it is what every command line tool prints and what people expect to compare by eye. And whichever format you use, MD5 remains unsuitable for security; Content-MD5 verifies transport integrity, not authenticity.
Frequently asked questions
Why is my Base64 MD5 44 characters long?
You encoded the 32-character hex string instead of the 16 raw bytes. Hash to binary first.
Is a Base64 MD5 more secure than hex?
No. It is the same digest in a different alphabet, with identical weaknesses.
How long is a Base64 MD5?
24 characters including the trailing "=" padding, or 22 without it.
Ready to try it?
Open the free browser-based Hash generator and apply what you just read — no sign-up, runs locally.
Open the Hash generator tool