nebulae.dotChaCha20 0.1.8

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

dotChaCha20

A minimal, fast, cross-platform ChaCha20 wrapper for .NET applications.

This library provides access to the ChaCha20 stream cipher, which is known for its speed and security. It is designed to be easy to use and integrates seamlessly with .NET applications. Binaries are provided for Windows x64, Linux x64 and macOS (x64 & Apple Silicon).

The underlying optimized implementation is taken verbatim from BoringSSL maintained by Google, ensuring that it is both efficient and secure.

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 AVX2 on x64 & neon on Apple Silicon.
  • Easy to use: Simple API for encryption and decryption.
  • Secure: Based on the ChaCha20 cipher, which is widely recognized for its security.
  • Minimal dependencies: No external dependencies required (all are included), making it lightweight and easy to integrate.

Requirements

  • .NET 8.0 or later
  • Advanced SIMD capable CPU (AVX2 support for x64 on any OS or neon on Apple Silicon M-Series)
  • Windows x64, Linux x64, or macOS (x64 / M-series arm64)

Usage

For those that are unaware, ChaCha20 is a stream ciper that is used for encrypting data in a way that is both fast and secure. It operates on 64-byte blocks and uses a 256-bit key. The encrypt function called with the key & nonce will encrypt the plaintext (the message), and re-running the encrypt function with the same key & nonce on the encrypted message will yield the original plaintext.


using System;
using nebulae.dotChaCha20;

public class Example
{
    public static void Main()
    {
        // Be sure to call Init() to load the native library
        ChaCha20.Init();

        // ------------------------
        //  Example 1: byte[] API
        // ------------------------
        byte[] key1 = new byte[32];
        byte[] nonce1 = new byte[12];
        byte[] plaintext1 = new byte[32];
        new Random(1).NextBytes(plaintext1); // fill with random data

        byte[] ciphertext1 = new byte[32];
        byte[] decrypted1 = new byte[32];

        ChaCha20.Encrypt(key1, nonce1, counter: 1, plaintext1, ciphertext1);
        ChaCha20.Encrypt(key1, nonce1, counter: 1, ciphertext1, decrypted1);

        Console.WriteLine("Byte[] round-trip success: " + plaintext1.AsSpan().SequenceEqual(decrypted1));

        // ------------------------------
        //  Example 2: Span<byte> API
        // ------------------------------
        Span<byte> key2 = stackalloc byte[32];
        Span<byte> nonce2 = stackalloc byte[12];
        Span<byte> plaintext2 = stackalloc byte[32];
        Span<byte> ciphertext2 = stackalloc byte[32];
        Span<byte> decrypted2 = stackalloc byte[32];

        new Random(2).NextBytes(plaintext2);

        ChaCha20.Encrypt(key2, nonce2, counter: 1, plaintext2, ciphertext2);
        ChaCha20.Encrypt(key2, nonce2, counter: 1, ciphertext2, decrypted2);

        Console.WriteLine("Span<byte> round-trip success: " + plaintext2.SequenceEqual(decrypted2));
    }
}


Installation

You can install the package via NuGet:


$ dotnet add package nebulae.dotChaCha20

Or via git:


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


License

MIT

Roadmap

Unless there are vulnerabilities found in the ChaCha20 cipher, 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.2.1 58 9/7/2025
0.2.0 62 9/6/2025
0.1.10 130 8/31/2025
0.1.9 107 8/9/2025
0.1.8 207 8/6/2025
0.1.7 134 7/16/2025
0.1.6 140 7/16/2025
0.1.5 139 7/16/2025
0.1.4 301 6/11/2025