basenc — Base64 and URL-Safe Encoding
basenc (GNU coreutils) encodes and decodes data in various base formats. Its key advantage over the older base64 utility is native support for URL-safe base64 (--base64url), which replaces + and / with - and _ to avoid URL-escaping headaches. 1
Common operations
# Encode to standard base64
echo "$STRING" | basenc --base64
# Encode to URL-safe base64
echo "$STRING" | basenc --base64url
# Decode from standard base64
echo "$BASE64_STRING" | basenc -d --base64
# Decode from URL-safe base64
echo "$BASE64_STRING" | basenc -d --base64urlSupported encodings
basenc supports more than just base64:
| Encoding | Flag |
|---|---|
| Base64 | --base64 |
| URL-safe base64 | --base64url |
| Base32 | --base32 |
| Base32 hex | --base32hex |
| Base16 (hex) | --base16 |
| Base2 (binary) | --base2msbf, --base2lsbf |
| Z85 | --z85 |
When to prefer basenc over base64
- URL-safe output:
--base64urlavoids the need for post-processingtr '+/' '-_'. 2 - Multiple formats: one tool for base32, base16, and base64.
- Consistency:
basencis the modern coreutils frontend;base64is maintained for compatibility. 3
Sources
Related: powershell-base64-encoding, linux-reconnaissance-commands