black electronics

CLI Encoding & Decoding

Common commands for encoding and decoding text, base64 and hex from the command line.

Encoded strings show up constantly in loot, config files and captured traffic. These are the conversions I reach for most often to make sense of them.

Encode

Terminal window
# Convert text from UTF-8 to UTF-16LE, then to base64 (useful for values that need to match Windows' native string encoding)
echo -n "example|value|here" | iconv -f UTF-8 -t UTF-16LE | base64 -w 0

Decode

Terminal window
cat encoded_file | base64 -d # Decode base64
Terminal window
cat hex_file | xxd -r -p # Convert hex back to text
Terminal window
python -c "print(HEX_value)" # Convert hex to decimal
Useful LinksPentest PayloadsCheat Sheets