Wiry.Base32

Base32 and ZBase32 encoding library


Keywords
core, coreclr, z-base-32, rfc4648, cross-platform, base32, netstandard, clr, zbase32, netcore
License
MIT
Install
Install-Package Wiry.Base32 -Version 1.1.1

Documentation

Wiry.Base32

NuGet License

Base32 and ZBase32 encoding and decoding library.

AppVeyor (Windows): AppVeyor

Travis CI (Linux): Travis CI

.NET compatibility:

  • .NET Framework (4.5.2+)
  • .NET Core (netstandard 1.6+)

Installation

To install Wiry.Base32, run the following command in the Package Manager Console

PM> Install-Package Wiry.Base32

Usage example

using System;
using System.Linq;
using System.Text;
using Wiry.Base32;

namespace Base32ConsoleApp
{
    public class Program
    {
        public static void Main()
        {
            // original text
            string text = "Hello, World!";
            Console.WriteLine($"Text: '{text}'");
            byte[] inputBytes = Encoding.ASCII.GetBytes(text);

            // Convert to RFC 4648 Base32 string
            string base32 = Base32Encoding.Standard.GetString(inputBytes);
            Console.WriteLine($"base32: '{base32}'");

            // Convert to z-base-32 string
            string zbase32 = Base32Encoding.ZBase32.GetString(inputBytes);
            Console.WriteLine($"z-base-32: '{zbase32}'");

            // Convert data back and check it
            byte[] decodedBase32 = Base32Encoding.Standard.ToBytes(base32);
            if (inputBytes.SequenceEqual(decodedBase32))
                Console.WriteLine("Convert back from base32 successfully!");

            byte[] decodedZBase32 = Base32Encoding.ZBase32.ToBytes(zbase32);
            if (inputBytes.SequenceEqual(decodedZBase32))
                Console.WriteLine("Convert back from z-base-32 successfully!");
        }
    }
}

Output:

Text: 'Hello, World!'
base32: 'JBSWY3DPFQQFO33SNRSCC==='
z-base-32: 'jb1sa5dxfoofq551pt1nn'
Convert back from base32 successfully!
Convert back from z-base-32 successfully!

Benchmarks

Benchmark repository

Test configuration: Win10 x64 @ Intel Core 2 Quad Q9550.

Test 1: 1000000 repeats with 64 bytes of data:

Library (alphabetical order) Encoding Decoding
.NET Base64 (baseline) 219 ms 371 ms
Albireo.Base32 v1.0.1 954 ms 3790 ms
Base3264-UrlEncoder v1.0.1 2581 ms 46706 ms
SimpleBase v1.2.0 513 ms 642 ms
WallF.BaseNEncodings v1.0.0 603 ms 3528 ms
Wiry.Base32 v1.0.5 372 ms 410 ms

Test 2: random data size from 0 to 100 bytes (500 sessions by 20000 repeats):

Encode duration

Decode duration

References

License

Copyright (c) Dmitry Razumikhin, 2016-2017.

Licensed under the MIT License.