vrk base
Try it in your browser
# Encodes text as base64. Use decode to go back.
Press RUN. Nothing leaves your browser.files you can cat:
Edit the command and press RUN. Open the full playground for more recipes, or install vrk to run it on your own files.
vrk base encodes and decodes base64, base64url, hex, and base32 with identical behavior on every platform.
The problem
base64 behaves differently on macOS and Linux. macOS wraps output at 76 characters. -w0 disables wrapping on Linux but does not exist on macOS. -d means decode on macOS, --decode on Linux. A script that works locally breaks in CI on a different OS.
The solution
vrk base encodes and decodes base64, base64url, hex, and base32 with identical behavior on every platform. It has two subcommands: encode and decode. It strips one trailing newline from stdin, so echo input works as you expect. It has no platform-specific flags.
Before and after
Before
# macOS
echo 'hello' | base64
# Linux
echo 'hello' | base64 -w0
# Different flags, different output
After
echo 'hello' | vrk base encode --to base64
Example
echo 'hello' | vrk base encode --to base64
Exit codes
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | Invalid encoded input (bad characters, wrong padding) |
| 2 | Missing subcommand, –to/–from missing or unsupported |
Flags
| Flag | Short | Type | Description |
|---|---|---|---|
--to | string | Target encoding: base64, base64url, hex, base32 (encode subcommand) | |
--from | string | Source encoding: base64, base64url, hex, base32 (decode subcommand) | |
--quiet | -q | bool | Suppress stderr output |
Supported encodings
vrk base encodes and decodes text as base64, base64url, hex, or base32.
| Encoding | Flag value | Example output |
|---|---|---|
| Base64 | base64 | aGVsbG8= |
| Base64url | base64url | aGVsbG8 (no padding, URL-safe) |
| Hex | hex | 68656c6c6f |
| Base32 | base32 | NBSWY3DP |
How it works
Encode
$ echo 'hello' | vrk base encode --to base64
aGVsbG8=
$ echo 'hello' | vrk base encode --to hex
68656c6c6f
$ echo 'hello' | vrk base encode --to base64url
aGVsbG8
Decode
$ echo 'aGVsbG8=' | vrk base decode --from base64
hello
$ echo '68656c6c6f' | vrk base decode --from hex
hello
Trailing newline handling
echo adds a newline. vrk base removes exactly one trailing newline before it encodes, so echo 'hello' and printf 'hello' give the same result. To keep the newline, use printf 'hello\n'.
Pipeline integration
Decode a base64 field from JSON
echo "$JWT_PAYLOAD" | vrk base decode --from base64url | jq .
Encode content for embedding in JSON
ENCODED=$(cat binary-file | vrk base encode --to base64)
echo "{\"data\":\"$ENCODED\"}" | vrk kv set --ns cache payload
When it fails
Invalid base64 input:
$ echo '!!invalid!!' | vrk base decode --from base64
error: base: invalid base64 input
$ echo $?
1
Missing encoding flag:
$ echo 'hello' | vrk base encode
usage error: base: --to is required
$ echo $?
2