Base32 and ZBase32 encoding and decoding library.
- .NET Framework (4.5.2+)
- .NET Core (netstandard 1.6+)
To install Wiry.Base32, run the following command in the Package Manager Console
PM> Install-Package Wiry.Base32
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!
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):
Copyright (c) Dmitry Razumikhin, 2016-2017.
Licensed under the MIT License.