Branca 0.8.1

dotnet add package Branca --version 0.8.1
                    
NuGet\Install-Package Branca -Version 0.8.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="Branca" Version="0.8.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Branca" Version="0.8.1" />
                    
Directory.Packages.props
<PackageReference Include="Branca" />
                    
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 Branca --version 0.8.1
                    
#r "nuget: Branca, 0.8.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 Branca@0.8.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=Branca&version=0.8.1
                    
Install as a Cake Addin
#tool nuget:?package=Branca&version=0.8.1
                    
Install as a Cake Tool

Branca

A .NET Standard 2.1 library for generating and validating Branca tokens.

Branca tokens are authenticated and encrypted API tokens using modern crypto. They use IETF XChaCha20-Poly1305 AEAD symmetric encryption to create encrypted and tamperproof tokens, base62 encoded to be URL safe. The payload is an arbitrary sequence of bytes: a JSON object, plain text or binary data serialized by MessagePack or Protocol Buffers.

Usage

Configure a BrancaService with a 32-byte secret key:

using Branca;

BrancaKey key = BrancaKey.Generate();

BrancaService branca = new(key);

Existing keys load from hexadecimal, Base64Url, Base62 or raw bytes:

BrancaKey key = BrancaKey.FromHex(
  "73757065727365637265746b6579796f7573686f756c646e6f74636f6d6d6974");

Encode a payload into a token:

string token = branca.Encode("Hello, World!");

Decode and validate a token:

if (branca.TryDecode(token, out byte[] payload))
{
  string message = Encoding.UTF8.GetString(payload);
}

Tokens are valid for an hour by default; configure BrancaSettings to change the token lifetime and other options. Older keys listed in PreviousKeys keep validating after a rotation, and ClockSkewInSeconds tolerates clock drift between issuers and validators. A single BrancaService instance is safe for concurrent use.

The library targets .NET Standard 2.1 and .NET 10, and is trimming and Native AOT compatible.

See the repository for detailed documentation and examples.

License

Branca is free software, licensed under the GNU Lesser General Public License v3.0 or later.

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.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 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 (1)

Showing the top 1 NuGet packages that depend on Branca:

Package Downloads
Branca.AspNetCore

ASP.NET Core authentication handler for Branca tokens.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.8.1 445 7/11/2026
0.8.0 130 7/11/2026
0.7.0 25,128 8/18/2023
0.6.0 1,178 4/15/2022
0.5.0 625 4/15/2022
0.4.0 762 4/15/2022 0.4.0 is deprecated because it is no longer maintained.
0.3.0 551 8/23/2021
0.2.0 562 8/21/2021