Hash generator · Guide

SHA256 Online Base64: Convert a Digest Between Hex and Base64

A SHA-256 digest is 32 raw bytes. Hex is the usual way to write them, Base64 is the compact alternative several protocols require. Converting between the two is a re-encoding, never a re-hash.

The two representations

Hex spells each byte as two characters — 64 characters total. Base64 packs three bytes into four characters — 44 characters with the trailing "=" padding, 43 without.

Base64url, used in JWTs and URLs, swaps + and / for - and _ and usually drops the padding. If a digest contains hyphens or underscores, it is base64url and must be translated before a standard decoder will read it.

Producing Base64 directly

The essential step is hashing to raw binary before encoding, rather than encoding the hex string:

Shell
# shell
openssl dgst -sha256 -binary file.txt | base64

# PHP — third argument returns raw bytes
base64_encode(hash('sha256', $data, true));

# Python
import base64, hashlib
base64.b64encode(hashlib.sha256(data).digest())

If your result is 88 characters, you Base64-encoded the 64-character hex string by mistake. The correct output is 44.

Where each format is expected

Base64: Subresource Integrity attributes in HTML (integrity="sha256-..."), HTTP Digest headers, JWT signatures, certificate pinning entries, Kubernetes manifests.

Hex: command line checksums, package manifests, Git object ids, database columns, anything a human compares by eye.

When a spec shows a digest with a sha256- prefix and characters like + or /, it wants Base64 — pasting hex there silently fails the check.

Frequently asked questions

How long is a Base64 SHA-256?

44 characters including padding, 43 without.

Does converting to Base64 change the hash?

No. It is the same 32 bytes written differently.

Why does my SRI integrity check fail?

Usually hex was supplied where Base64 is required, or the file changed after the digest was computed.

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