SodiumBindings 1.1.0

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

SodiumBindings

SodiumBindings provides .NET bindings for the libsodium cryptography library. The API uses Span<T> and ReadOnlySpan<T> so callers can control allocations and handle sensitive buffers directly.

Requirements

Installation

dotnet add package SodiumBindings

Getting started

Initialize libsodium once during application startup before using any other SodiumBindings API:

using SodiumBindings;

SodiumHelper.Initialize();

The following example encrypts and decrypts a message with SecretBox:

using System.Security.Cryptography;
using System.Text;
using SodiumBindings;

SodiumHelper.Initialize();

byte[] key = RandomNumberGenerator.GetBytes(SecretBox.KeyBytes);
byte[] nonce = RandomNumberGenerator.GetBytes(SecretBox.NonceBytes);
byte[] message = Encoding.UTF8.GetBytes("Hello, libsodium!");
byte[] ciphertext = new byte[SecretBox.GetCiphertextLength(message.Length)];

SecretBox.Encrypt(ciphertext, message, nonce, key);

byte[] plaintext = new byte[SecretBox.GetPlaintextLength(ciphertext.Length)];
if (!SecretBox.Decrypt(plaintext, ciphertext, nonce, key))
{
    throw new CryptographicException("The ciphertext failed authentication.");
}

Console.WriteLine(Encoding.UTF8.GetString(plaintext));

CryptographicOperations.ZeroMemory(key);
CryptographicOperations.ZeroMemory(plaintext);

Security notes

  • Consult the libsodium documentation before choosing algorithms and parameters for a production protocol.
  • Allocate output buffers using the size constants and length helpers exposed by each API.
  • Never reuse a nonce with the same key unless the underlying libsodium construction explicitly permits it.

License

SodiumBindings is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
1.1.0 114 9/6/2026
1.0.0 109 8/21/2026