hex1
Base 16/32/64 encode/decode data to standard output
Part of basez(1).
Usage
basez [OPTION] ...
[FILE]
hex [OPTION] ...
[FILE]
base16 [OPTION] ...
[FILE]
base32plain [OPTION] ...
[FILE]
base32hex [OPTION] ...
[FILE]
base64plain [OPTION] ...
[FILE]
base64url [OPTION] ...
[FILE]
base64mime [OPTION] ...
[FILE]
base64pem [OPTION] ...
[FILE]
Overview
BaseZ encodes/decodes base16, base32, base32hex, base64 or base64url data stream per RFC 4648; MIME base64 Content-Transfer-Encoding per RFC 2045; or PEM Printable Encoding per RFC 1421.
Base16 encoding produces a multiple of two-character blocks in hexadecimal notation [0-9a-f]. It needs no padding and preserves the sort order of the encoded data. Decoding is case insensitive.
Base32 encoded stream is a multiple of eight-character blocks consisting of letters and numbers [A-Z2-7]. Numbers easily confused with some letters are skipped intentionally to make this encoding suitable for storage on -- or transport over -- any medium or data transport mechanism, including non-case-preserving barcodes or printed out strings that could be spelled out and typed in by humans. If needed, the last encoded block is padded with equal sign end padding. Appearance of the padding character [=] at the end of the encoded steam can be avoided by encoding data of size divisible by 5. Base32 decoding is case insensitive.
Base32hex encoding works the same way as base32 but with an alternative character-set [0-9a-v] to preserve the encoded data sort order. This encoding should not be confused with base32.
Base64 encoded stream is a multiple of four-character blocks using uppercase letters, lowercase letters, numbers, plus and slash [A-Za-z0-9+/]. It uses equal sign [=] for end padding. Base64 decoding is case sensitive. It has an option to convert local native text line breaks into canonical CRLF sequences prior to encoding or to convert CRLF sequences into native text line breaks after the decoding.
Base64url encoding is technically the same as base64 but instead of the plus and slash signs [+/] it uses minus and underscore [-_]. Appearance of the padding character [=] in the encoded stream can be avoided by encoding data of size divisible by 3.
Base64mime and base64pem are the same encodes as base64 but with encoded stream line length limit of 76 and 64 characters respectively. PEM decoding ignores all white and non-printable characters; MIME decoding ignores all characters outside of the encode character-set.
Options
When no FILE is specified or when FILE is -, read standard input. When multiple conflicting options appear, the last option wins.
-
-d, -D, --decode -
Decode. By default ignore the space and newline characters. The
--strict,--ignore-all-space, and--ignore-garbageoptions provide alternative behaviors. Default option for unhex command.
-
-r, --strict -
Do not ignore any characters outside of the encode character-set on decoding.
-
-s, --ignore-all-space -
Ignore all white and non-printable ASCII characters on decoding. Default for base64pem decoding.
-
-g, --ignore-garbage -
Ignore all characters outside of the encode character-set on decoding. Default for base64mime decoding.
-
-x, --hex, --base16 -
Base16 coding. Default for base16, hex and unhex commands.
-
-j, --base32 -
Base32 coding. Default for base32 and base32plain commands.
-
-e --base32hex -
Base32hex coding. Default for base32hex command.
-
-c, --capitals, --upper-case -
Output upper case letters on encoding, if applicable.
-
-l, --lower-case -
Output lower case letters on encoding, if applicable.
-
-a, --base64 -
Base64 coding. Default for basez, base64 and base64plain commands.
-
-u, --base64url -
Base64url coding. Default for base64url command.
-
-p, --base64pem -
PEM printable coding. Default for base64pem command.
-
-m, --base64mime -
MIME base64 coding. Default for base64mime command.
-
-t, --text -
Convert native text line breaks into CRLF sequences prior to encoding or convert CRLF sequences into native text line breaks after decoding. This option applies to all variants of base64 codings.
-
-w N, -b N, --wrap=N, --break=N -
Set encoded stream line length limit to N characters. The default value is 76 for base64mime encode, 64 for base64pem encode, infinity for all other encodes. To disable any appearance of EOL characters in the encoded stream, set to 0.
-
-i FILEIN, --input=FILEIN -
Input file. Default is standard input. When FILEIN is -, read stdin.
-
-o FILEOUT, --output=FILEOUT -
Output file. Default is standard output. When FILEOUT is -, write to stdout.
-
-h, --help -
Display help.
-
--version -
Display program version information.
Examples
Base16 decode a string:
-
echo 4a6f650a | hex --decode
Inspect output of a command:
-
echo Joe | hex --wrap 2
Base32 encode a string:
-
printf "Hi People\n" | base32plain
MIME base64 encode a binary file to stdout per RFC 2045:
-
base64mime FILE
MIME base64 encode a text file to stdout per RFC 2045:
-
base64mime --text FILE
Base64 encode a file per RFC 4648
-
base64plain FILE > base64.rfc4648.file
Releases
11 releases since Debian 2.2 (Potato); the text changed 5 times.
--base16 since Debian 9 (Stretch);
--base32 since Debian 9 (Stretch);
--base32hex since Debian 9 (Stretch);
--base64 since Debian 9 (Stretch);
--base64mime since Debian 9 (Stretch);
--base64pem since Debian 9 (Stretch);
--base64url since Debian 9 (Stretch);
--break since Debian 9 (Stretch);
--capitals since Debian 9 (Stretch);
--decode since Debian 9 (Stretch);
--hex since Debian 9 (Stretch);
--ignore-all-space since Debian 9 (Stretch);
--ignore-garbage since Debian 9 (Stretch);
--input since Debian 9 (Stretch);
--lower-case since Debian 9 (Stretch);
--output since Debian 9 (Stretch);
--strict since Debian 9 (Stretch);
--upper-case since Debian 9 (Stretch);
--version since Debian 9 (Stretch);
--wrap since Debian 9 (Stretch);
-D since Debian 9 (Stretch);
-a since Debian 9 (Stretch);
-c since Debian 9 (Stretch);
-d since Debian 9 (Stretch);
-g since Debian 9 (Stretch);
-i since Debian 9 (Stretch);
-l since Debian 9 (Stretch);
-m since Debian 9 (Stretch);
-o since Debian 9 (Stretch);
-p since Debian 9 (Stretch);
-w since Debian 9 (Stretch);
-x since Debian 9 (Stretch).
--bold until Debian 6.0 (Squeeze);
--colorstring1 until Debian 6.0 (Squeeze);
--colorstring2 until Debian 6.0 (Squeeze);
--enablesiso until Debian 6.0 (Squeeze);
--ieuc until Debian 6.0 (Squeeze);
--isjis until Debian 6.0 (Squeeze);
--iunknown until Debian 6.0 (Squeeze);
--oeuc until Debian 6.0 (Squeeze);
--ojis until Debian 6.0 (Squeeze);
--osjis until Debian 6.0 (Squeeze);
--restore until Debian 6.0 (Squeeze);
--underline until Debian 6.0 (Squeeze);
-E until Debian 6.0 (Squeeze);
-S until Debian 6.0 (Squeeze);
-U until Debian 6.0 (Squeeze);
-cs1 until Debian 6.0 (Squeeze);
-cs2 until Debian 6.0 (Squeeze);
-ie until Debian 6.0 (Squeeze);
-is until Debian 6.0 (Squeeze);
-iu until Debian 6.0 (Squeeze);
-oe until Debian 6.0 (Squeeze);
-oj until Debian 6.0 (Squeeze);
-os until Debian 6.0 (Squeeze);
-siso until Debian 6.0 (Squeeze).