Base64 encode/decode · Guide
Base64 Encode a File Linux: Files on the Command Line
Encoding a file to Base64 is a one-liner on every platform. The details that matter are line wrapping, which breaks single-line consumers, and getting the equivalent right on Windows.
Linux and macOS
# encode / decode
base64 keystore.jks > keystore.b64
base64 -d keystore.b64 > keystore.jks
# single line, which is what most consumers need
base64 -w 0 keystore.jks > keystore.b64 # GNU / Linux
base64 -i keystore.jks | tr -d '\n' # macOS / BSDGNU base64 wraps at 76 characters by default. macOS has no -w flag at all, which is why cross-platform scripts pipe through tr -d instead.
Windows
certutil is present on every Windows install and does both directions, though it adds header lines that must be stripped for a raw value:
certutil -encode input.bin encoded.txt
certutil -decode encoded.txt output.bin
# PowerShell, no header lines
[Convert]::ToBase64String([IO.File]::ReadAllBytes("input.bin"))The PowerShell form is cleaner for scripting since it returns exactly the encoded string. Note it loads the whole file into memory.
Why you would do this
Environment variables and CI secret stores cannot hold newlines reliably, so binary credentials — keystores, service account keys, certificates — are stored Base64-encoded as one line and decoded at deploy time.
It is also how you move a small binary through a text-only channel: a chat message, a ticket comment, a config file. Remember the 33% size increase, and that encoding provides no confidentiality whatsoever — an encoded keystore in a public repository is an exposed keystore.
Frequently asked questions
How do I stop base64 wrapping lines?
base64 -w 0 on Linux; pipe through tr -d on macOS, where -w does not exist.
Is there a file size limit?
The command streams, so it handles files far larger than memory. Browser-based tools do not.
Does encoding protect a secret?
No. It is trivially reversible. Encrypt if the content must stay private.
Ready to try it?
Open the free browser-based Base64 encode/decode and apply what you just read — no sign-up, runs locally.
Open the Base64 encode/decode tool