Base 64 Encoding

Base 64 code is used in email to encode a sequence of 8-bit bytes as a longer sequence of ASCII graphic characters. It is defined in Internet RFC162045 and also in RFC 4648. This section describes the functions for converting to and from this code.

Command: base64-encode-region beg end &optional no-line-break

This function converts the region from beg to end into base 64 code. It returns the length of the encoded text. An error is signaled if a character in the region is multibyte, i.e., in a multibyte buffer the region must contain only characters from the charsets ascii, eight-bit-control and eight-bit-graphic.

Normally, this function inserts newline characters into the encoded text, to avoid overlong lines. However, if the optional argument no-line-break is non-nil, these newlines are not added, so the output is just one long line.

Command: base64url-encode-region beg end &optional no-pad

This function is like base64-encode-region, but it implements the URL variant of base 64 encoding, per RFC 4648, and it doesn’t insert newline characters into the encoded text, so the output is just one long line.

If the optional argument no-pad is non-nil then this function doesn’t generate the padding (=).

Function: base64-encode-string string &optional no-line-break

This function converts the string string into base 64 code. It returns a string containing the encoded text. As for base64-encode-region, an error is signaled if a character in the string is multibyte.

Normally, this function inserts newline characters into the encoded text, to avoid overlong lines. However, if the optional argument no-line-break is non-nil, these newlines are not added, so the result string is just one long line.

Function: base64url-encode-string string &optional no-pad

Like base64-encode-string, but generates the URL variant of base 64, and doesn’t insert newline characters into the encoded text, so the result is just one long line.

If the optional argument no-pad is non-nil then this function doesn’t generate the padding.

Command: base64-decode-region beg end &optional base64url

This function converts the region from beg to end from base 64 code into the corresponding decoded text. It returns the length of the decoded text.

The decoding functions ignore newline characters in the encoded text.

If optional argument base64url is non-nil, then padding is optional, and the URL variant of base 64 encoding is used.

Function: base64-decode-string string &optional base64url

This function converts the string string from base 64 code into the corresponding decoded text. It returns a unibyte string containing the decoded text.

The decoding functions ignore newline characters in the encoded text.

If optional argument base64url is non-nil, then padding is optional, and the URL variant of base 64 encoding is used.

Copyright © 1990-1996, 1998-2021 Free Software Foundation, Inc.
Licensed under the GNU GPL license.
https://www.gnu.org/software/emacs/manual/html_node/elisp/Base-64.html