UrlBase64 1.0.0

Suggested Alternatives

UrlBase64 1.0.1

Additional Details

A method with an incorrect signature was used in version UrlBase64 1.0 to decode `Span<byte>` with a `byte[]` return type instead of `string`. The overload with that return type has been renamed to `DecodeUtf8(...)` while `Decode(Span<byte> ...)` now returns `string` just like the regular `Decode(byte[] ...)` routine.

There is a newer version of this package available.
See the version list below for details.
dotnet add package UrlBase64 --version 1.0.0                
NuGet\Install-Package UrlBase64 -Version 1.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="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add UrlBase64 --version 1.0.0                
#r "nuget: UrlBase64, 1.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.
// Install UrlBase64 as a Cake Addin
#addin nuget:?package=UrlBase64&version=1.0.0

// Install UrlBase64 as a Cake Tool
#tool nuget:?package=UrlBase64&version=1.0.0                

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.

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);
}

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));

TWFyeSBoYWQgYSBsaXR0bGUgbGFtYg TWFyeSBoYWQgYSBsaXR0bGUgbGFtYg==

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-2018.

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

NuGet packages (9)

Showing the top 5 NuGet packages that depend on UrlBase64:

Package Downloads
H.Necessaire.Runtime

A Core Framework for Rapid Application Development

Enmeshed.Tooling

Package Description

SingBoxLib

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

GeometryDashAPI

API for game Geometry Dash

UwpCache

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

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.0 78,076 5/16/2024
2.0.0-preview2 112 4/18/2024
2.0.0-preview1 1,496 10/28/2023
1.0.1 148,150 9/27/2023
1.0.0 10,884 9/5/2023 1.0.0 is deprecated.
0.1.2 1,184,492 2/2/2018
0.1.1 5,667 9/21/2017
0.1.0 3,210 7/13/2017

1.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 encoded error with inputs of a certain length.


0.1:

   * Initial release