Table of Contents

BinaryEncodings Class

Definition

Namespace
Bodu.Text.Encoding
Assembly
Bodu.Text.Encoding.dll
Package
Bodu.Text.Encoding 1.0.0
Source
BinaryEncodings.cs

Provides ready-made IBinaryEncoding instances for every variant supported by the library.

public static class BinaryEncodings
Inheritance
BinaryEncodings
Inherited Members

Examples

// Pre-bound singleton - no allocation per call.
IBinaryEncoding hex    = BinaryEncodings.Base16Upper;
IBinaryEncoding jwt    = BinaryEncodings.Base64UrlSafe;
IBinaryEncoding bitcoin = BinaryEncodings.Base58;

string encoded = jwt.Encode(payload);
byte[] decoded = jwt.Decode(encoded);

// Look up by name - accepts canonical names and well-known aliases.
IBinaryEncoding fromConfig = BinaryEncodings.Get(appConfig["encoding"] ?? "base64");
IBinaryEncoding fromAlias  = BinaryEncodings.Get("hex");           // same as Base16Lower

Remarks

Each property returns a thread-safe singleton bound to a specific variant. The pattern is analogous to System.Text.Encoding.UTF8: a constant instance that can be passed around, stored in configuration, or used through IBinaryEncoding by code that must remain agnostic to the concrete encoding.

Code that knows the encoding at compile time should prefer the static methods on Base16, Base32, Base64, Base58, or Base85 - they are slightly faster (no virtual dispatch) and surface variant-specific options (line breaks, padding control, alternate variants) that the unified interface intentionally hides.

Properties

Ascii85

Gets the Adobe Ascii85 encoding (4-byte groups → 5 characters; z shortcut for all-zero groups; partial trailing groups permitted).

public static IBinaryEncoding Ascii85 { get; }

Property Value

IBinaryEncoding

Base16Lower

Gets the lower-case hexadecimal (Base16) encoding - the same canonical form Encode(byte[], BaseFormattingOptions) produces with default options.

public static IBinaryEncoding Base16Lower { get; }

Property Value

IBinaryEncoding

Base16Upper

Gets the upper-case hexadecimal (Base16) encoding - matches RFC 4648 §8 canonical case and ToHexString(byte[]).

public static IBinaryEncoding Base16Upper { get; }

Property Value

IBinaryEncoding

Base32

Gets the RFC 4648 §6 Standard Base32 encoding (alphabet A-Z 2-7, padded with =).

public static IBinaryEncoding Base32 { get; }

Property Value

IBinaryEncoding

Base32Crockford

Gets the Crockford Base32 encoding (human-friendly alphabet excluding I, L, O, U; no padding by default).

public static IBinaryEncoding Base32Crockford { get; }

Property Value

IBinaryEncoding

Base32Hex

Gets the RFC 4648 §7 base32hex (HexExtended) Base32 encoding (alphabet 0-9 A-V, padded with =).

public static IBinaryEncoding Base32Hex { get; }

Property Value

IBinaryEncoding

Base32ZBase32

Gets the z-base-32 encoding (human-oriented lowercase alphabet; no padding by default).

public static IBinaryEncoding Base32ZBase32 { get; }

Property Value

IBinaryEncoding

Base45

Gets the RFC 9285 Base45 encoding - the compact alphanumeric encoding used to carry binary data inside a QR code's Alphanumeric mode (no padding).

public static IBinaryEncoding Base45 { get; }

Property Value

IBinaryEncoding

Base58

Gets the Bitcoin/Flickr Base58 encoding - the alphabet used by Bitcoin addresses, IPFS CIDs, Solana, and many derivative protocols.

public static IBinaryEncoding Base58 { get; }

Property Value

IBinaryEncoding

Base58Ripple

Gets the Ripple Base58 encoding (XRP ledger alphabet, a permutation of Bitcoin/Flickr).

public static IBinaryEncoding Base58Ripple { get; }

Property Value

IBinaryEncoding

Base62

Gets the GMP-style Base62 encoding (alphabet 0-9 A-Z a-z; leading zero bytes preserved as leading 0 characters).

public static IBinaryEncoding Base62 { get; }

Property Value

IBinaryEncoding

Base64

Gets the RFC 4648 §4 Standard Base64 encoding (alphabet A-Z a-z 0-9 + /, padded with =).

public static IBinaryEncoding Base64 { get; }

Property Value

IBinaryEncoding

Base64Mime

Gets the RFC 2045 MIME Base64 encoding (Standard alphabet with mandatory 76-character line wrapping).

public static IBinaryEncoding Base64Mime { get; }

Property Value

IBinaryEncoding

Base64UrlSafe

Gets the RFC 4648 §5 URL- and filename-safe Base64 encoding (alphabet A-Z a-z 0-9 - _; no padding by default).

public static IBinaryEncoding Base64UrlSafe { get; }

Property Value

IBinaryEncoding

Base85Git

Gets the Git-style Base85 encoding (Git binary-patch alphabet with compact, self-delimiting partial groups; no z shortcut or Adobe delimiters).

public static IBinaryEncoding Base85Git { get; }

Property Value

IBinaryEncoding

Z85

Gets the ZeroMQ Z85 encoding (RFC 32; shell-safe alphabet; input must be a multiple of four bytes).

public static IBinaryEncoding Z85 { get; }

Property Value

IBinaryEncoding

Methods

Get(string)

Returns the encoding for the supplied case-insensitive name. The recognised names are the values returned by each instance's Name: "base16", "base16-lower", "base16-upper", "base32", "base32hex", "base32-crockford", "z-base-32", "base45", "base64", "base64-urlsafe", "base64-mime", "base58", "base58-ripple", "base62", "ascii85", "base85-git", "z85".

public static IBinaryEncoding Get(string name)

Parameters

name string

The encoding name.

Returns

IBinaryEncoding

The matching IBinaryEncoding instance.

Exceptions

ArgumentNullException

Thrown when name is null.

ArgumentException

Thrown when no matching encoding is registered.

Applies to

ProductVersions
.NET8, 10