base64
Visionary Software Solutions Base64: the RFC 4648 §4 base64 and §5 base64url binary-to-text codecs
Encode bytes as RFC 4648 Base64 text and decode that text back to bytes. The text is typed by its alphabet, and decoding accepts only text an RFC 4648 encoder writes.
Key Concepts
Codec contract
Role. rfc4648.Factory and rfc4648url.Factory each make a software.visionary.rfc4648.Codec over their alphabet. deserialize encodes bytes as Encoded data, whose toString() is the text; read takes text to encoded data, and serialize decodes that to bytes.
Alphabets
Role. Base64 is RFC 4648 §4's alphabet, A–Z, a–z, 0–9, + and /. Base64Url is §5's, which has - and _ in place of + and /, so its text needs no percent-encoding in a URL or a filename. Each is an enum whose constants pick their glyphs; §4's refuses - and _, and §5's refuses + and /.
Padding
Role. Each factory's PADDED codec ends a short final group with =, so its text is a multiple of four symbols. Its UNPADDED codec writes no padding. Choose the one the receiving protocol expects; each refuses the other's short final group.
Strict decoding
Role. A character outside the alphabet is refused with DemandFailedException. A line break is outside every alphabet, so text broken into lines, as PEM and MIME write it, is refused, as RFC 4648 §3.1 and §3.3 require. So are a final group of one symbol, a missing, extra or misplaced pad, and a final symbol whose fill bits are not zero. serialize refuses before it returns. A codec decodes only the text it encodes for the resulting bytes.
Usage
Round-trip bytes with padded Base64
import java.util.Arrays;
import software.visionary.base64.rfc4648.Base64;
import software.visionary.base64.rfc4648.Factory;
import software.visionary.rfc4648.Codec;
class Base64RoundTrip {
public static void main(String[] args) {
Codec<Base64> codec = Factory.PADDED.create();
byte[] original = {0x12, 0x34, (byte) 0xAB};
String written = codec.deserialize(original).toString();
System.out.println(written + " " + Arrays.equals(original, codec.serialize(codec.read(written))));
}
}
Write a URL-safe segment with unpadded base64url
import software.visionary.base64.rfc4648url.Base64Url;
import software.visionary.base64.rfc4648url.Factory;
import software.visionary.rfc4648.Codec;
class Base64UrlSegment {
public static void main(String[] args) {
Codec<Base64Url> codec = Factory.UNPADDED.create();
byte[] octets = {3, (byte) 236, (byte) 255, (byte) 224, (byte) 193};
System.out.println(codec.deserialize(octets));
}
}
Dependencies
software.visionary:rfc4648:2026.10.13at Compilesoftware.visionary.reboot:jacoco-closure:2026.10.13at Testing
Views
Drawn from the release. A link in a view opens its source at the release tag.