VOOZH about

URL: https://www.nuget.org/packages/UrlBase64/

⇱ NuGet Gallery | UrlBase64 2.0.0




👁 Image
UrlBase64 2.0.0

dotnet add package UrlBase64 --version 2.0.0
 
 
NuGet\Install-Package UrlBase64 -Version 2.0.0
 
 
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="UrlBase64" Version="2.0.0" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="UrlBase64" Version="2.0.0" />
 
Directory.Packages.props
<PackageReference Include="UrlBase64" />
 
Project file
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 UrlBase64 --version 2.0.0
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: UrlBase64, 2.0.0"
 
 
#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 UrlBase64@2.0.0
 
 
#: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=UrlBase64&version=2.0.0
 
Install as a Cake Addin
#tool nuget:?package=UrlBase64&version=2.0.0
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

UrlBase64

UrlBase64 is a package for all versions of the .NET Framework and .NET Core, which supports the creation of url-safe base64 encoding. UrlBase64 provides symmetric routines to both encode and later decode data in a fashion that makes it safe for use on the general web and as input to ASP.NET web applications (under IIS or similar).

Installation

UrlBase64 is available via nuget and the Visual Studio package manager. To install, simply run the following in the package manager console:

Install-Package UrlBase64

Or search for UrlBase64 in the Visual Studio package manager.

Basic Usage

All functions are contained in the static UrlBase64 class, found in the NeoSmart.Utils namespace.

using NeoSmart.Utils;

void UsageSample()
{
 var foo = Encoding.UTF8.GetBytes("foo");
 var encoded = UrlBase64.Encode(foo);
 var decoded = UrlBase64.Decode(encoded);

 var bar = Encoding.UTF8.GetString(decoded);

 Assert.AreEqual("foo", bar);
}

Advanced Usage

The UrlBase64 library comes with several variants of the Encode() and Decode() routines that can be used for better performance. In particular:

  • It is possible (and, assuming it works for you, preferable) to use EncodeUtf8() or one of the other Encode() variants that return a span or array of ASCII/UTF-8 bytes (being the URL-safe base64-encoded result) instead of a string for better performance and lower memory usage.
  • Similarly, it is preferred to use the Decode(byte[]) or Decode(ReadOnlySpan<byte>) overloads instead of Decode(string).
  • There are overloads of both Encode() and Decode() which can complete in an allocation-free manner. These take a second Span<byte> buffer parameter that provides the scratch space to decode into and return a Span<byte> instead of a byte[] that represents the result of the encode or decode operation. This permits you to allocate a buffer once and reuse it for all subsequent calls (or use something like ArrayPool<byte>, etc) instead of having the Encode() or Decode() operation allocate a new buffer for the result each time.
  • To ensure you are passing in a buffer of sufficient size (otherwise the Encode() or Decode() operations will throw!), use UrlBase64.GetMaxEncodedLength() or UrlBase64.GetMaxDecodedLength() to obtain an adequately sized buffer to encode/decode into.

Padding Options (Encoding)

UrlBase64 supports two different padding modes (internally: PaddingPolicy) for generating base64 content:

public enum PaddingPolicy
{
 Discard,
 Preserve,
}

The PaddingPolicy option controls the behavior of UrlBase64 when encoding content that does not fall on a 4-character (output) boundary. Per RFC 4648, base64 specifies that an "optional depending on the circumstances" trailing = sign is used to pad the output to be a multiple of 4 characters long. UrlBase64 supports both padded and unpadded output via an optional PaddingPolicy parameter to UrlBase64.Encode controlling this behavior. The default behavior at this time is to omit the trailing padding given that it a) can (and usually is) be inferred automatically when dropped from the encoded output, and b) utilizes a symbol that requires encoding when used in URLs.

var bytes = Encoding.UTF8.GetBytes("Mary had a little lamb");
Console.WriteLine(bytes, UrlBase64.Encode(bytes, PaddingPolicy.Discard));
Console.WriteLine(bytes, UrlBase64.Encode(bytes, PaddingPolicy.Preserve));

which emits the following:

TWFyeSBoYWQgYSBsaXR0bGUgbGFtYg

TWFyeSBoYWQgYSBsaXR0bGUgbGFtYg==

License and Copyright

UrlBase64 is developed by Mahmoud Al-Qudsi of NeoSmart Technologies. UrlBase64 is released under the terms of the MIT Public License. Copyright NeoSmart Technologies 2017-2024.

Product Versions Compatible and additional computed target framework versions.
.NET net5.0 net5.0 was computed.  net5.0-windows net5.0-windows was computed.  net6.0 net6.0 was computed.  net6.0-android net6.0-android was computed.  net6.0-ios net6.0-ios was computed.  net6.0-maccatalyst net6.0-maccatalyst was computed.  net6.0-macos net6.0-macos was computed.  net6.0-tvos net6.0-tvos was computed.  net6.0-windows net6.0-windows was computed.  net7.0 net7.0 was computed.  net7.0-android net7.0-android was computed.  net7.0-ios net7.0-ios was computed.  net7.0-maccatalyst net7.0-maccatalyst was computed.  net7.0-macos net7.0-macos was computed.  net7.0-tvos net7.0-tvos was computed.  net7.0-windows net7.0-windows was computed.  net8.0 net8.0 was computed.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 was computed.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 was computed.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows net10.0-windows was computed. 
.NET Core netcoreapp1.0 netcoreapp1.0 was computed.  netcoreapp1.1 netcoreapp1.1 was computed.  netcoreapp2.0 netcoreapp2.0 was computed.  netcoreapp2.1 netcoreapp2.1 was computed.  netcoreapp2.2 netcoreapp2.2 was computed.  netcoreapp3.0 netcoreapp3.0 was computed.  netcoreapp3.1 netcoreapp3.1 was computed. 
.NET Standard netstandard1.0 netstandard1.0 is compatible.  netstandard1.1 netstandard1.1 was computed.  netstandard1.2 netstandard1.2 was computed.  netstandard1.3 netstandard1.3 was computed.  netstandard1.4 netstandard1.4 was computed.  netstandard1.5 netstandard1.5 was computed.  netstandard1.6 netstandard1.6 was computed.  netstandard2.0 netstandard2.0 is compatible.  netstandard2.1 netstandard2.1 was computed. 
.NET Framework net20 net20 is compatible.  net35 net35 was computed.  net40 net40 is compatible.  net403 net403 was computed.  net45 net45 was computed.  net451 net451 was computed.  net452 net452 was computed.  net46 net46 was computed.  net461 net461 was computed.  net462 net462 was computed.  net463 net463 was computed.  net47 net47 was computed.  net471 net471 was computed.  net472 net472 was computed.  net48 net48 was computed.  net481 net481 was computed. 
MonoAndroid monoandroid monoandroid was computed. 
MonoMac monomac monomac was computed. 
MonoTouch monotouch monotouch was computed. 
Tizen tizen30 tizen30 was computed.  tizen40 tizen40 was computed.  tizen60 tizen60 was computed. 
Universal Windows Platform uap uap was computed.  uap10.0 uap10.0 was computed. 
Windows Phone wp8 wp8 was computed.  wp81 wp81 was computed.  wpa81 wpa81 was computed. 
Windows Store netcore netcore was computed.  netcore45 netcore45 was computed.  netcore451 netcore451 was computed. 
Xamarin.iOS xamarinios xamarinios was computed. 
Xamarin.Mac xamarinmac xamarinmac was computed. 
Xamarin.TVOS xamarintvos xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (11)

Showing the top 5 NuGet packages that depend on UrlBase64:

Package Downloads
H.Necessaire.Runtime

A Core Framework for Rapid Application Development

SingBoxLib

Configure and run sing-box with ease. Based on sing-box's official documentation.

Enmeshed.Tooling

Package Description

GeometryDashAPI

API for game Geometry Dash

UwpCache

A persistent object cache for your Windows 10 uwp and uap applications.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on UrlBase64:

Repository Stars
timokoessler/2FAGuard
A modern and secure Windows app for managing your 2FA authentication codes.
Version Downloads Last Updated
2.0.0 428,382 5/16/2024
2.0.0-preview2 244 4/18/2024
2.0.0-preview1 1,691 10/28/2023
1.0.1 195,822 9/27/2023
1.0.0 11,640 9/5/2023 1.0.0 is deprecated.
0.1.2 2,098,312 2/2/2018
0.1.1 6,145 9/21/2017
0.1.0 3,941 7/13/2017

2.0.0:
   * Add support for allocation-free encode/decode
   * Add new binary/UTF-8 Decode() method to decode url-safe base64-encoded bytes directly,
     without going through a string representation.
   * Fix regression introduced in 1.x that breaks decoding REGULAR base64 with UrlBase64.Decode()

1.0.0:
   * Support for Span<T> and co.

0.1.2:
   * New PaddingPolicy option to specify output padding
   * Lower .NET Standard requirement to 1.0

0.1.1:
   * Fixed an encode error with inputs of a certain length.

0.1:
   * Initial release