Philiprehberger.BaseEncoding
0.1.1
dotnet add package Philiprehberger.BaseEncoding --version 0.1.1
NuGet\Install-Package Philiprehberger.BaseEncoding -Version 0.1.1
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="Philiprehberger.BaseEncoding" Version="0.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Philiprehberger.BaseEncoding" Version="0.1.1" />
<PackageReference Include="Philiprehberger.BaseEncoding" />
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 Philiprehberger.BaseEncoding --version 0.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Philiprehberger.BaseEncoding, 0.1.1"
#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 Philiprehberger.BaseEncoding@0.1.1
#: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=Philiprehberger.BaseEncoding&version=0.1.1
#tool nuget:?package=Philiprehberger.BaseEncoding&version=0.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Philiprehberger.BaseEncoding
Base32, Base62, and Base64URL encoding and decoding — URL-safe, padding-free alternatives to standard Base64.
Installation
dotnet add package Philiprehberger.BaseEncoding
Usage
using Philiprehberger.BaseEncoding;
var encoded = BaseEncoding.Base32.Encode(new byte[] { 72, 101, 108, 108, 111 });
var decoded = BaseEncoding.Base32.Decode(encoded);
Encode and Decode
using Philiprehberger.BaseEncoding;
var data = System.Text.Encoding.UTF8.GetBytes("Hello, World!");
var base32 = BaseEncoding.Base32.Encode(data);
var original = BaseEncoding.Base32.Decode(base32);
// original == data
var base62 = BaseEncoding.Base62.Encode(data);
var restored = BaseEncoding.Base62.Decode(base62);
// restored == data
Base64URL for Tokens
using Philiprehberger.BaseEncoding;
var tokenBytes = new byte[32];
System.Security.Cryptography.RandomNumberGenerator.Fill(tokenBytes);
var token = BaseEncoding.Base64Url.Encode(tokenBytes);
// URL-safe string with no padding, safe for query strings and headers
var raw = BaseEncoding.Base64Url.Decode(token);
Base62 Short URLs
using Philiprehberger.BaseEncoding;
var id = BitConverter.GetBytes(123456789L);
var shortCode = BaseEncoding.Base62.Encode(id);
// Compact alphanumeric string suitable for short URLs
var decoded = BaseEncoding.Base62.Decode(shortCode);
API
| Method / Type | Description |
|---|---|
BaseEncoding.Base32 |
Static property returning an IBaseEncoder for RFC 4648 Base32 (no padding) |
BaseEncoding.Base62 |
Static property returning an IBaseEncoder for alphanumeric [0-9A-Za-z] encoding |
BaseEncoding.Base64Url |
Static property returning an IBaseEncoder for RFC 4648 section 5 Base64URL (no padding) |
IBaseEncoder.Encode(data) |
Encodes a byte array into a string |
IBaseEncoder.Decode(encoded) |
Decodes a string back into a byte array |
Development
dotnet build src/Philiprehberger.BaseEncoding.csproj --configuration Release
License
| Product | Versions 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 was computed. 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 was computed. 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.
-
net8.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.