The string to encode
Whether to encode using the URL-safe alphabet of RFC 4648 § 5 rather than the standard alphabet of
RFC 4648 § 4; defaults to false
The base64 representation of plain in the selected alphabet, with every isolated surrogate encoded as
U+FFFD
Encodes a string to base64.
Converts the input to UTF-8 bytes and encodes them in the standard alphabet of RFC 4648 § 4, retaining the trailing
=padding, or in the URL-safe variant of RFC 4648 § 5, substituting+//with-/_and stripping the trailing=padding.Text carrying isolated UTF-16 surrogates doesn't survive the round trip: UTF-8 conversion replaces each one with
U+FFFDREPLACEMENT CHARACTER, so decoding the result returns a string that differs fromplain. Test the input with strings!isWellFormed or sanitise it with strings!toWellFormed where the distinction matters.