NCode.Base64Url
2.0.1
Prefix Reserved
dotnet add package NCode.Base64Url --version 2.0.1
NuGet\Install-Package NCode.Base64Url -Version 2.0.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="NCode.Base64Url" Version="2.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NCode.Base64Url" Version="2.0.1" />
<PackageReference Include="NCode.Base64Url" />
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 NCode.Base64Url --version 2.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: NCode.Base64Url, 2.0.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 NCode.Base64Url@2.0.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=NCode.Base64Url&version=2.0.1
#tool nuget:?package=NCode.Base64Url&version=2.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
NCode.Base64Url
A high-performance .NET library for encoding and decoding base64url data as defined in RFC 4648 Section 5. Built with modern memory-efficient APIs including Span<T>, ReadOnlySequence<T>, and IBufferWriter<T>.
Features
- URL-Safe Encoding — Uses
-and_instead of+and/, making encoded data safe for URLs, filenames, and identifiers - No Padding — Omits trailing
=padding characters (decoder accepts both padded and unpadded input) - Zero-Allocation Options —
TryEncode/TryDecodemethods write directly to caller-provided buffers - Streaming Support — Full support for
ReadOnlySequence<T>for processing fragmented/pipelined data - Buffer Writer Integration — Direct output to
IBufferWriter<T>for high-throughput scenarios - High Performance — Optimized with unsafe code, lookup tables, and aggressive inlining
Installation
dotnet add package NCode.Base64Url
Quick Start
using NCode.Encoders;
// Encoding
byte[] data = { 0x48, 0x65, 0x6C, 0x6C, 0x6F }; // "Hello" in ASCII
string encoded = Base64Url.Encode(data); // Returns "SGVsbG8"
// Decoding
byte[] decoded = Base64Url.Decode("SGVsbG8"); // Returns original bytes
API Summary
Encoding Methods
| Method | Description |
|---|---|
GetCharCountForEncode(int) |
Calculates the output character count for a given byte count |
Encode(ReadOnlySpan<byte>) |
Encodes bytes to a base64url string |
Encode(ReadOnlySequence<byte>) |
Encodes a byte sequence to a base64url string |
Encode(ReadOnlySpan<byte>, IBufferWriter<char>) |
Encodes bytes directly to a buffer writer |
Encode(ReadOnlySequence<byte>, IBufferWriter<char>) |
Encodes a byte sequence directly to a buffer writer |
TryEncode(ReadOnlySpan<byte>, Span<char>, out int) |
Attempts to encode bytes to a provided character buffer |
TryEncode(ReadOnlySequence<byte>, Span<char>, out int) |
Attempts to encode a byte sequence to a provided character buffer |
Decoding Methods
| Method | Description |
|---|---|
GetByteCountForDecode(int) |
Calculates the output byte count for a given character count |
Decode(ReadOnlySpan<char>) |
Decodes a base64url string to a byte array |
Decode(ReadOnlySpan<char>, IBufferWriter<byte>) |
Decodes a base64url string directly to a buffer writer |
Decode(ReadOnlySequence<char>, IBufferWriter<byte>) |
Decodes a character sequence directly to a buffer writer |
TryDecode(ReadOnlySpan<char>, Span<byte>, out int) |
Attempts to decode a base64url string to a provided byte buffer |
TryDecode(ReadOnlySequence<char>, Span<byte>, out int) |
Attempts to decode a character sequence to a provided byte buffer |
Advanced Usage
Zero-Allocation Encoding
byte[] data = GetData();
int charCount = Base64Url.GetCharCountForEncode(data.Length);
Span<char> buffer = stackalloc char[charCount];
if (Base64Url.TryEncode(data, buffer, out int charsWritten))
{
// Use buffer[..charsWritten]
}
Zero-Allocation Decoding
ReadOnlySpan<char> encoded = "SGVsbG8";
int byteCount = Base64Url.GetByteCountForDecode(encoded.Length);
Span<byte> buffer = stackalloc byte[byteCount];
if (Base64Url.TryDecode(encoded, buffer, out int bytesWritten))
{
// Use buffer[..bytesWritten]
}
Using with IBufferWriter
var writer = new ArrayBufferWriter<char>();
int charsWritten = Base64Url.Encode(data, writer);
Target Frameworks
- .NET 8.0
- .NET 10.0
Release Notes
| Version | Changes |
|---|---|
| v1.0.0 | Initial release |
| v1.1.0 | Added support for ReadOnlySequence<T> |
| v1.1.1 | Added sequence overloads without buffer writer |
| v1.1.2 | Optimized single-segment sequence handling |
| v2.0.0 | Target .NET 8.0+ only |
| v2.0.1 | Updates to xmldoc and readme |
License
Licensed under the Apache License, Version 2.0.
| 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 is compatible. 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.
-
net10.0
- No dependencies.
-
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.
Built on 2026-01-17 17:14:43Z