# base64

`software.visionary:base64:2026.10.13` · https://codeberg.org/notations/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.** <code>rfc4648.Factory</code> and <code>rfc4648url.Factory</code> each make a <code>software.visionary.rfc4648.Codec</code> over their alphabet. <code>deserialize</code> encodes bytes as <code>Encoded</code> data, whose <code>toString()</code> is the text; <code>read</code> takes text to encoded data, and <code>serialize</code> decodes that to bytes.

### Alphabets

**Role.** <code>Base64</code> is RFC 4648 §4's alphabet, <code>A–Z</code>, <code>a–z</code>, <code>0–9</code>, <code>+</code> and <code>/</code>. <code>Base64Url</code> is §5's, which has <code>-</code> and <code>_</code> in place of <code>+</code> and <code>/</code>, 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 <code>-</code> and <code>_</code>, and §5's refuses <code>+</code> and <code>/</code>.

### Padding

**Role.** Each factory's <code>PADDED</code> codec ends a short final group with <code>=</code>, so its text is a multiple of four symbols. Its <code>UNPADDED</code> 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 <code>DemandFailedException</code>. 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. <code>serialize</code> refuses before it returns. A codec decodes only the text it encodes for the resulting bytes.

## Usage

Round-trip bytes with padded Base64

```java
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

```java
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.13` at Compile
- `software.visionary.reboot:jacoco-closure:2026.10.13` at Testing

