Gapotchenko.FX.Data.Encoding.Base32 2024.1.3

Prefix Reserved
dotnet add package Gapotchenko.FX.Data.Encoding.Base32 --version 2024.1.3                
NuGet\Install-Package Gapotchenko.FX.Data.Encoding.Base32 -Version 2024.1.3                
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="Gapotchenko.FX.Data.Encoding.Base32" Version="2024.1.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Gapotchenko.FX.Data.Encoding.Base32 --version 2024.1.3                
#r "nuget: Gapotchenko.FX.Data.Encoding.Base32, 2024.1.3"                
#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.
// Install Gapotchenko.FX.Data.Encoding.Base32 as a Cake Addin
#addin nuget:?package=Gapotchenko.FX.Data.Encoding.Base32&version=2024.1.3

// Install Gapotchenko.FX.Data.Encoding.Base32 as a Cake Tool
#tool nuget:?package=Gapotchenko.FX.Data.Encoding.Base32&version=2024.1.3                

Overview

The module provides the implementation of binary-to-text encoding algorithms belonging to the Base32 family.

Quick Start

Use the following code to get the textual representation of the specified data in Base32 encoding:

using Gapotchenko.FX.Data.Encoding;

var encodedText = Base32.GetString(data);

To get the data back from the textual representation, use the following method:

var decodedData = Base32.GetBytes(encodedText);

Static Methods vs Interface

Base32 encoding classes provide a set of convenient static methods that represent the most commonly used operations. For a more general and full use, however, the classes implement ITextDataEncoding interface which can be accessed via the Instance property of the corresponding encoding class.

Iterative Data Processing

If you need to encode the data iteratively then the following approach becomes handy:

var encoding = Base32.Instance;

// Create a streaming encoder that iteratively encodes the data and
// writes the encoded text to the specified text writer.
var stream = encoding.CreateEncoder(textWriter);

// Iteratively stream the data to encode.
stream.Write(...); // block 1
// ...
stream.Write(...); // block N

// Flush the data to the underlying text writer.
stream.Flush();

The same approach is valid for the decoding operation which is the opposite of the encoding:

var encoding = Base32.Instance;

// Create a streaming decoder that iteratively reads the encoded text
// from the specified text reader and decodes the data on the fly.
var stream = encoding.CreateDecoder(textReader);

// Iteratively stream the decoded data.
stream.Read(...); // block 1
// ...
stream.Read(...); // block N

The streaming encoder and decoder can be used to iteratively transcode the data from one encoding to another.

Available Base32 Algorithms

Base32 family of binary-to-text data encodings consists of several attested algorithms with predefined parameters:

Algorithm Gapotchenko.FX Implementation Alphabet Case-Sensitive Data Encoding Efficiency*
Base32 (standard, recommended) Base32 ABCDEFGHIJKLMNOPQRSTUVWXYZ234567 No 0.625
base32-hex Base32Hex 0123456789ABCDEFGHIJKLMNOPQRSTUV No 0.625
Crockford Base 32 CrockfordBase32 0123456789ABCDEFGHJKMNPQRSTVWXYZ*~$=U No 0.625
z-base-32 ZBase32 ybndrfg8ejkmcpqxot1uwisza345h769 No 0.625

* Data encoding efficiency is the ratio between the amount of original data and its encoded representation.

Among all other possibilities, it is recommended to use the standard Base32 algorithm which is provided by Base32 class.

All other predefined algorithms are provided by the corresponding classes of Gapotchenko.FX.Data.Encoding.Base32 module.

Custom Base32 Algorithms

Once in a while, you may encounter a custom Base32 algorithm that is neither widely known nor characterized. In that case, you can instantiate a custom data encoding algorithm with the desired parameters by hand. For example:

var encoding = new CustomBase32("ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ01234567");

If you want to formalize the custom algorithm even further, you may opt in to create a separate class for it with a convenient accessor property:

/// <summary>
/// Defines a custom Base32 data encoding algorithm.
/// </summary>
sealed class FooBase32 : CustomBase32
{
    FooBase32() :
        base("ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ01234567")
    {
    }

    public static FooBase32 Instance { get; } = new();
}

That will allow you to use the algorithm effortlessly from several places in the codebase later:

var encodedText = FooBase32.Instance.GetString(...);

Commonly Used Types

  • Gapotchenko.FX.Data.Encoding.Base32
  • Gapotchenko.FX.Data.Encoding.Base32Hex
  • Gapotchenko.FX.Data.Encoding.CrockfordBase32
  • Gapotchenko.FX.Data.Encoding.ZBase32

Other Modules

Let's continue with a look at some other modules provided by Gapotchenko.FX:

Or look at the full list of modules.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 is compatible.  netcoreapp2.2 was computed.  netcoreapp3.0 is compatible.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 is compatible.  net472 is compatible.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
2024.1.3 62 11/10/2024
2022.2.7 1,688 5/1/2022
2022.2.5 213 5/1/2022