brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: openssl base64 -d decodes base64 on any system that has OpenSSL

Openssl
~/tips/tip-openssl-base64-decode

echo 'aGVsbG8gd29ybGQ=' | openssl base64 -d

Encode and decode base64 with one command that works the same on Linux, macOS and BSD.

The base64 tool exists almost everywhere, but its flags differ between GNU and macOS. openssl base64 behaves the same on every machine with OpenSSL.

Encode, then decode:

printf 'hello world' | openssl base64
echo 'aGVsbG8gd29ybGQ=' | openssl base64 -d

The first prints aGVsbG8gd29ybGQ=, the second prints hello world again. I’d use printf instead of echo when encoding, because echo adds a newline that becomes part of the encoded value. That is a classic reason why a token or password stored in a Kubernetes secret or an .env file does not work.

OpenSSL wraps encoded output at 64 characters per line. For a single long line, which most config files and HTTP headers expect, add -A:

openssl base64 -A -in key.der

When decoding, the input also has to be in lines of at most 64 characters, unless you add -A there as well. Without it, a long one line value can decode to nothing at all, with no error. Base64url, the variant with - and _ used in JWTs, is not supported. Swap those characters back with tr '_-' '/+' first. And remember base64 is encoding, not encryption.

Further reading: OpenSSL: openssl-enc

More Openssl tips openssl s_client -connect 203.0.113.10:443 -servername example.com </dev/null | openssl x509 -noout -subject openssl x509 -in cert.pem -days 365 -signkey key.pem -out cert-new.pem printf %s hello | openssl dgst -sha256 -hmac secret openssl pkcs12 -legacy -in old.pfx -nokeys | openssl s_client -connect example.com:443 -servername example.com -quiet -keylogfile keys.log All Openssl tips (34) All topics

Link