Shells and files
base64
Encodes bytes as text, or decodes base64 text back to the exact bytes — a public, keyless transform, not encryption.
base64 FILE rewrites the bytes as the A-Z a-z 0-9 + / alphabet with = padding; base64 -d
turns that text back into the original bytes. There is no key and no secret: the recipe is RFC 4648, so anyone reverses
it, which is why base64 hides content without protecting it. A wall of that alphabet ending in = is the
fingerprint of base64, so a decode is the first thing to try on a blob that looks like noise. It reads a file or
standard input, so it chains with other decoders — base64 -d file | xxd -r -p peels a base64 layer and then a hex
layer underneath.
base64 command usage
base64 [-d] [-w COLS] [FILE]
Options
-
-d - decode base64 text back into bytes (the common case when reading a sample)
-
-w 0 - write the output on one line instead of wrapping at 76 columns
-
-i - ignore characters that are not in the base64 alphabet instead of erroring
base64 examples
-
base64 -d sample.b64 - Decodes the base64 in the file and prints the bytes underneath.
-
base64 -d sample.b64 | xxd -r -p - Peels a base64 layer, then turns the hex under it back into bytes.
-
echo -n 'Hillside' | base64 - Encodes the text; out comes
SGlsbHNpZGU=, the=padding the end. -
cat secret.b64 | base64 -d | head - Reads the encoded file from a pipe and shows the start of what it decodes to.
Pitfalls
- Decoding is not decryption: a clean decode proves the data was only encoded, so it was never protected in the first place.
invalid input: the text has characters outside the alphabet (a stray header, wrapping, or it was never base64).-iskips them.