Class Overview
SIMPLE_BASE64 provides RFC 4648 compliant Base64 encoding and decoding
for Eiffel applications. It supports both standard Base64 and URL-safe Base64URL variants.
Creation
Initialize the encoder. No parameters required.
Encoding Features
encode (a_input: STRING): STRING
Encode a string to standard Base64 with padding.
Contracts
encode_bytes (a_bytes: ARRAY [NATURAL_8]): STRING
Encode a byte array to standard Base64. Useful for binary data.
Contracts
encode_url (a_input: STRING): STRING
Encode to URL-safe Base64URL without padding. Uses - and _ instead of + and /.
Contracts
encode_url_with_padding (a_input: STRING): STRING
Encode to URL-safe Base64URL with padding preserved.
Contracts
Decoding Features
decode (a_input: STRING): STRING
Decode a Base64 or Base64URL string back to the original string.
Contracts
decode_bytes (a_input: STRING): ARRAY [NATURAL_8]
Decode Base64 to a byte array. Automatically handles both standard and URL-safe formats.
Contracts
decode_url (a_input: STRING): STRING
Decode a URL-safe Base64URL string. Alias for decode with clearer intent.
Contracts
Validation Features
is_valid_base64 (a_string: STRING): BOOLEAN
Check if a string is valid standard Base64 (with proper length and characters).
Format: Length must be a multiple of 4. Characters must be A-Z, a-z, 0-9, +, /, or = (padding).
Contracts
is_valid_base64_url (a_string: STRING): BOOLEAN
Check if a string is valid URL-safe Base64URL.
Characters must be A-Z, a-z, 0-9, -, _, or = (padding). Length does not need to be a multiple of 4.
Contracts
Conversion Features
to_url_safe (a_base64: STRING): STRING
Convert standard Base64 to URL-safe format. Replaces + with - and / with _.
Contracts
to_standard (a_base64url: STRING): STRING
Convert URL-safe Base64URL to standard format. Replaces - with + and _ with /.
Contracts
Constants
| Constant | Value | Description |
|---|---|---|
Standard_alphabet |
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/ |
Standard Base64 alphabet (RFC 4648) |
Url_safe_alphabet |
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_ |
URL-safe Base64URL alphabet (RFC 4648) |
Padding_char |
= |
Padding character |