LibSodium.Net
0.10.0-alpha
Prefix Reserved
This is a prerelease version of LibSodium.Net.
dotnet add package LibSodium.Net --version 0.10.0-alpha
NuGet\Install-Package LibSodium.Net -Version 0.10.0-alpha
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="LibSodium.Net" Version="0.10.0-alpha" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LibSodium.Net" Version="0.10.0-alpha" />
<PackageReference Include="LibSodium.Net" />
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 LibSodium.Net --version 0.10.0-alpha
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: LibSodium.Net, 0.10.0-alpha"
#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.
#addin nuget:?package=LibSodium.Net&version=0.10.0-alpha&prerelease
#tool nuget:?package=LibSodium.Net&version=0.10.0-alpha&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
🔐 Modern cryptography for .NET 8+
Idiomatic .NET bindings for libsodium with a Span-based, zero-allocation API.
Includes AEAD encryption (XChaCha20-Poly1305, AES256-GCM, AEGIS), public-key cryptography (CryptoBox
, Sealed Boxes
, CryptoSign
), authenticated streaming (SecretStream
), secure memory, and more.
Built for Windows, Linux, macOS, iOS, Android, tvOS, and Mac Catalyst.
Fast, memory-safe, allocation-free. AOT-ready with LibraryImport
.
Tested in GitHub Actions using AOT builds on Windows, Linux and macOS
📚 Documentation: https://libsodium.net/
// XChaCha20Poly1305 — Combined mode, auto-nonce, with AAD
Span<byte> key = stackalloc byte[XChaCha20Poly1305.KeyLen];
RandomGenerator.Fill(key);
var aad = Encoding.UTF8.GetBytes("context");
var data = Encoding.UTF8.GetBytes("Hello");
var ciphertext = new byte[data.Length + XChaCha20Poly1305.MacLen + XChaCha20Poly1305.NonceLen];
XChaCha20Poly1305.Encrypt(ciphertext, data, key, aad: aad);
var decrypted = new byte[data.Length];
XChaCha20Poly1305.Decrypt(decrypted, ciphertext, key, aad: aad);
var isWorking = decrypted.SequenceEqual(data);
Console.WriteLine($"It works: {isWorking}");
// SecretStream — Xchacha20-Poly1305 based authenticated encryption for streams
Span<byte> key = stackalloc byte[32];
RandomGenerator.Fill(key);
var helloData = Encoding.UTF8.GetBytes("Hello LibSodium.Net!");
using var plaintextStream = new MemoryStream();
using var ciphertextStream = new MemoryStream();
using var decryptedStream = new MemoryStream();
plaintextStream.Write(helloData);
plaintextStream.Position = 0;
SecretStream.Encrypt(plaintextStream, ciphertextStream, key);
ciphertextStream.Position = 0;
SecretStream.Decrypt(ciphertextStream, decryptedStream, key);
decryptedStream.Position = 0;
var isWorking = decryptedStream.ToArray().SequenceEqual(helloData);
Console.WriteLine($"It works: {isWorking}");
// CryptoBox — Authenticated encryption using public-key cryptography
Span<byte> senderPk = stackalloc byte[CryptoBox.PublicKeyLen];
Span<byte> senderSk = stackalloc byte[CryptoBox.PrivateKeyLen];
Span<byte> recipientPk = stackalloc byte[CryptoBox.PublicKeyLen];
Span<byte> recipientSk = stackalloc byte[CryptoBox.PrivateKeyLen];
CryptoBox.GenerateKeypair(senderPk, senderSk);
CryptoBox.GenerateKeypair(recipientPk, recipientSk);
var message = Encoding.UTF8.GetBytes("Top secret");
var ciphertext = new byte[message.Length + CryptoBox.MacLen + CryptoBox.NonceLen];
CryptoBox.EncryptWithKeypair(ciphertext, message, recipientPk, senderSk);
var decrypted = new byte[message.Length];
CryptoBox.DecryptWithKeypair(decrypted, ciphertext, senderPk, recipientSk);
Console.WriteLine($"It works: {decrypted.SequenceEqual(message)}");
Product | Versions 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
- libsodium (>= 1.0.20.1)
- System.Memory (>= 4.6.0)
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.10.0-alpha | 0 | 5/20/2025 |
0.9.0-alpha | 28 | 5/18/2025 |
0.8.0-alpha | 72 | 5/17/2025 |
0.7.0-alpha | 191 | 5/15/2025 |
0.6.0-alpha | 190 | 5/13/2025 |
0.5.0-alpha | 76 | 5/4/2025 |
0.4.0-alpha | 40 | 5/3/2025 |
0.3.0-alpha | 67 | 4/19/2025 |
0.2.0-alpha | 148 | 4/17/2025 |
0.1.0-alpha | 104 | 4/6/2025 |