ZBase32 1.0.0

dotnet add package ZBase32 --version 1.0.0
                    
NuGet\Install-Package ZBase32 -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ZBase32" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ZBase32" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="ZBase32" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ZBase32 --version 1.0.0
                    
#r "nuget: ZBase32, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ZBase32@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ZBase32&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=ZBase32&version=1.0.0
                    
Install as a Cake Tool

ZBase32

A modern, high-performance .NET library for Z-Base-32 encoding and decoding.

This implementation is optimized for speed and low memory allocation by leveraging Span<T> and other modern .NET features.

What is Z-Base-32?

Z-Base-32 is a Base32 encoding variant designed by Zooko Wilcox-O'Hearn to be more human-friendly. It uses a custom alphabet that minimizes visual ambiguity between characters (e.g., 1, l, i) and is case-insensitive. It is a great choice for generating short, memorable, and easily transcribable identifiers.

Features

  • Fast and Efficient: Optimized for high throughput and minimal memory usage.
  • Modern API: Uses Span<T> and ReadOnlySpan<T> for zero-allocation operations where possible.
  • Simple Static Methods: A straightforward ZBase32Encoder class with static Encode and Decode methods.
  • Case-Insensitive Decoding: Adheres to the Z-Base-32 specification by treating uppercase and lowercase characters as equivalent during decoding.
  • Convenience Methods: Includes helpers for encoding/decoding UTF-8 strings directly.
  • Supports: .NET 8, 9 and 10

Installation

Install the package from NuGet using the .NET CLI:

dotnet add package ZBase32

Usage

The library exposes a single static class ZBase32.ZBase32Encoder.

Basic Encoding and Decoding

To encode a byte array into a Z-Base-32 string:

using ZBase32;

byte[] data = { 0xF8, 0x3E, 0x7A, 0x13, 0x8D, 0x95, 0x3E, 0x56 };
string encoded = ZBase32Encoder.Encode(data);

Console.WriteLine(encoded);

To decode a Z-Base-32 string back into a byte array:

using ZBase32;

string encoded = "64385t78983xyr4o";
byte[] decoded = ZBase32Encoder.Decode(encoded);

Working with UTF-8 Strings

The library includes helper methods to work directly with UTF-8 strings.

using System.Text;
using ZBase32;

// Encoding a string
string originalText = "Hello, World!";
string encodedText = ZBase32Encoder.EncodeUtf8String(originalText);

Console.WriteLine(encodedText);

// Decoding back to a string
string decodedText = ZBase32Encoder.DecodeToUtf8String(encodedText);
Console.WriteLine(decodedText);

High-Performance Usage with Span<T>

For performance-critical scenarios, you can use the Span<T>-based overloads to avoid array allocations.

using ZBase32;

// Encoding from a ReadOnlySpan<byte>
ReadOnlySpan<byte> dataSpan = new byte[] { 0xDE, 0xAD, 0xBE, 0xEF };
string encoded = ZBase32Encoder.Encode(dataSpan);

Console.WriteLine(encoded);

// Decoding to a byte[] from a ReadOnlySpan<char>
ReadOnlySpan<char> encodedSpan = "tuex3z61".AsSpan();
byte[] decoded = ZBase32Encoder.Decode(encodedSpan);

Performance

This library was designed with performance as a primary goal.

  • Span-Based Core: The core logic operates on spans to eliminate unnecessary memory allocations and copies.
  • Array Pooling: For encoding larger data sets, ArrayPool<T> is used to rent and return buffers, reducing GC pressure.
  • Optimized Lookups: Decoding uses a pre-computed array for O(1) character-to-value lookups.

License

This library is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 144 11/8/2025