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