nebulae.dotXChaCha20Poly1305 0.1.1

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

dotXChaCha20Poly1305

A high-performance, minimal, cross-platform wrapper around BoringSSL's xchacha20 poly1305 encryption and decryption implementation (ietf draft-irtf-cfrg-xchacha-03).

The native backend is compiled directly from BoringSSL's xchacha20poly1305 and related modules - ensuring constant-time cryptographic operations and production-grade optimizations across Windows, Linux, and macOS.

Tests are included and available in the Github repo.

NuGet


Features

  • Cross-platform: Works on Windows, Linux, and macOS (x64 & Apple Silicon).
  • High performance: Optimized for speed, leveraging native SIMD-enabled code.
  • Easy to use: Simple API for key exchange.
  • Secure: Uses Google's BoringSSL implementation, which is widely trusted in the industry.
  • Minimal dependencies: No external dependencies required (all are included), making it lightweight and easy to integrate.

Requirements

  • .NET 8.0 or later
  • Windows x64, Linux x64, or macOS (x64 & Apple Silicon)

Usage


using nebulae.dotXChaCha20Poly1305;
using System.Security.Cryptography;

// 32?byte key (store/handle securely!)
byte[] key = RandomNumberGenerator.GetBytes(32);

// 24?byte nonce - MUST be unique per (key, message)
byte[] nonce = RandomNumberGenerator.GetBytes(24);

// Optional AAD (not encrypted, but authenticated)
byte[] aad = "header".GetBytesUtf8();

// Your plaintext
byte[] plaintext = "hello, xchacha".GetBytesUtf8();

// Encrypt returns ciphertext || 16?byte tag
byte[] ct = XChaCha20Poly1305.Encrypt(key, nonce, plaintext, aad);

// Decrypt returns original plaintext (throws on auth failure)
byte[] pt = XChaCha20Poly1305.Decrypt(key, nonce, ct, aad);

With Spans


ReadOnlySpan<byte> keySpan   = key;
ReadOnlySpan<byte> nonceSpan = nonce;
ReadOnlySpan<byte> aadSpan   = aad;
ReadOnlySpan<byte> ptSpan    = plaintext;

byte[] ct2 = XChaCha20Poly1305.Encrypt(keySpan, nonceSpan, ptSpan, aadSpan);
byte[] pt2 = XChaCha20Poly1305.Decrypt(keySpan, nonceSpan, ct2, aadSpan);

API


public static class XChaCha20Poly1305
{
    // Encrypt: returns ciphertext || 16-byte tag
    public static byte[] Encrypt(
        ReadOnlySpan<byte> key32,
        ReadOnlySpan<byte> nonce24,
        ReadOnlySpan<byte> plaintext,
        ReadOnlySpan<byte> aad = default);

    // Decrypt: returns plaintext; throws CryptographicException on failure
    public static byte[] Decrypt(
        ReadOnlySpan<byte> key32,
        ReadOnlySpan<byte> nonce24,
        ReadOnlySpan<byte> ciphertextWithTag,
        ReadOnlySpan<byte> aad = default);
}


Installation

You can install the package via NuGet:


$ dotnet add package nebulae.dotXChaCha20Poly1305

Or via git:


$ git clone https://github.com/nebulaeonline/dotXChaCha20Poly1305.git
$ cd dotXChaCha20Poly1305
$ dotnet build


License

MIT

Roadmap

Unless there are vulnerabilities found, there are no plans to add any new features.

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

Version Downloads Last Updated
0.1.1 105 8/9/2025
0.1.0 135 8/8/2025