BAS

Synopsis

HELP:   Convert Base16/32/64/85 encoded data to binary data
TYPE:   OBJECT
SYNTAX: BAS(BUFSIZ=num,RECCNT=num,RECLEN=num,METHOD=BASE16/BASE32/BASE64,MODE=BLOCK/RECORD,CHRSET=NONE/SYSTEM/ASCII/UCS1/UTF8/EBCDIC/UCS2BE/UTF16BE/UCS2LE/UTF16LE/UCS4BE/UTF32BE/UCS4LE/UTF32LE/LOCAL,CRCCHK,ARMCHK,RSTCHK,SKPNOB,TARGET=PGP/CRY/ZIP/BIN/CHR/TXT/XML)

Description

The base converter can be used to convert data from binary format to printable text and vice versa using one of a couple of base encoding schemes (RFC 4648). When writing, binary data is encoded, when reading, encoded text is decoded. Encoding data to a different base results in expansion of the data. The ratio of expansion depends on the base used.

Most base encoding schemes append some padding bytes to the end of output data to pad it to a multiple of a specific length. As a result, encoding and decoding can be performed in one of two modes:

The block mode converts the input data as one large block of binary data. Padding will only be added at the end of the output file. This mode is the default for any type of input data, unless specified otherwise. This implies that record-based data will not retain record boundaries after encoding. As the output is printable text when encoding, it can optionally be split into multiple lines. The 'line' length parameter specifies after how many characters a line is wrapped. The line delimiter can be configured, but can also be omitted, which is useful to write the output record-oriented. When writing record-oriented, each output line results in one record. Note that if the 'line' length parameter is specified and a line delimiter is set, then the total maximum record length will be line length plus the length of the delimiter.

The record mode can be useful if the input data is record-based. In record mode, each record is encoded independently, which results in retaining the ability to access specific records by only decoding those specific records. Each output record is padded as required by the respective encoding scheme. Due to base encoding resulting in expansion of the data, the resulting records will be longer after encoding and shrink when decoding. To read a file that has been encoded in record mode, setting mode=record is mandatory. Otherwise, the result might be garbage.

The character set used (ASCII or EBCDIC) can also be configured. By default, the system-specific character set is used.

Mainly for PGP support, the component supports optional ASCII armor (also in EBCDIC) headers and trailers around the base encoded data (see RFC4880), but can also be used for other data and is independent of the encoding method (Base16/32/64). ASCII-armored data data is wrapped into lines, which can be written as records or as blocks with lines and delimiters. The default line length is 72 if no length is specified. When reading, the trailer string can optionally be verified to match the header string.

Another feature for OpenPGP support is a CRC checksum that is appended to the data. This is also optional and usable independently of the data, the encoding schema and the ASCII armor support. When writing, a switch can be enabled to add a CRC24 checksum conforming to RCF4880 for Base64 encodings. The other encoding schemas use the same mechanism to append a checksum to the base encoded data, but use another CRC variant. Base16 uses CRC32 and Base32 uses CRC40, known from the GSM network. When reading, a switch enables verification of this checksum. By default, no CRC verification is done. Since the checksum is optional, it is useless to calculate the CRC just to find out that there is no CRC appended to the data that can be compared against. If the verification fails, you get an error. If the verification is successful, you get an informational. If there is no checksum appended for verification, you get a warning. The same is true if verification is not requested, but a checksum is found.

With the TARGET selection you can limit the valid target formats after base decoding. For example, this can be used to ensure, that a base decoding is only done, if the result XML or a PGP message or a compressed data stream.

Arguments