A small, dependency-free Base45 encoding and decoding utility for .NET, implementing draft-faltstrom-base45-03 (the encoding used, among others, by the EU Digital COVID Certificate).
- Encode/decode between raw bytes and Base45 strings.
- String helpers that treat text as UTF-8.
- Strict decoding: rejects illegal characters, invalid lengths, and out-of-range groups.
- Allocation-friendly
Spanoverloads on modern targets. - Multi-targets
netstandard2.0,net8.0,net9.0, andnet10.0.
The package is published to GitHub Packages. Add the source once (replacing
USERNAME and TOKEN with a GitHub username and a personal access token that has the
read:packages scope):
dotnet nuget add source "https://nuget.pkg.github.com/iupsilon/index.json" \
--name github-iupsilon --username USERNAME --password TOKEN --store-password-in-clear-textThen reference it from your project:
dotnet add package Base45Utility<PackageReference Include="Base45Utility" Version="1.6.0" />Base45 is a lightweight, stateless type; a single instance can be reused.
using Base45Utility;
var base45 = new Base45();
// From a string (encoded as UTF-8)
string encoded = base45.Encode("Hello world"); // "%69 VD82EK4F.KEA2"
// From raw bytes
byte[] bytes = System.Text.Encoding.UTF8.GetBytes("Hello world");
string encodedFromBytes = base45.Encode(bytes); // same resultvar base45 = new Base45();
const string input = "%69 VD82EK4F.KEA2";
byte[] decodedBytes = base45.Decode(input); // raw bytes
string decodedText = base45.DecodeAsString(input); // "Hello world" (UTF-8)For hot paths, zero/low-allocation overloads are available:
var base45 = new Base45();
// Encode directly from a span of bytes
ReadOnlySpan<byte> payload = stackalloc byte[] { 1, 2, 3 };
string encoded = base45.Encode(payload);
// Decode into a caller-provided buffer; returns the number of bytes written
Span<byte> destination = stackalloc byte[32];
int written = base45.Decode("%69 VD82EK4F.KEA2".AsSpan(), destination);- String overloads assume UTF-8 for both directions.
- Empty input round-trips to empty output.
nullinput throwsArgumentNullException.DecodethrowsInvalidOperationExceptionfor an illegal character, an invalid length (a Base45 string length is always3nor3n+2), or a group that decodes to a value outside the valid byte/two-byte range.- The
Spandecode overload throwsArgumentExceptionif the destination buffer is too small.
Licensed under the Apache License, Version 2.0.