NCode.Buffers 5.0.1

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

NCode.Buffers

CI Coverage Target framework License

Pinned, pooled .NET buffers that zero themselves on dispose, for keys and other secrets, plus fixed-size buffer writers and string splitting without substring copies.

Installation

dotnet add package NCode.Buffers

The target frameworks are the ones the package's .csproj declares; they are listed on nuget.org's Frameworks tab and shown by the badge above. CHANGELOG.md records when a framework is added or dropped and which release line to stay on. The package depends on Nerdbank.Streams, whose Sequence<T> the pooled buffer writers return.

Example

This example derives a key from a password, verifies an HMAC-SHA256 signature with it, and zeroes the derived key and the expected MAC when the method returns.

using System.Security.Cryptography;
using NCode.Buffers;

public static class Signatures
{
    public static bool VerifySignature(
        ReadOnlySpan<byte> password,
        ReadOnlySpan<byte> salt,
        ReadOnlySpan<byte> payload,
        ReadOnlySpan<byte> signature
    )
    {
        // A pinned, pooled 32-byte key, zeroed when keyOwner is disposed.
        using var keyOwner = BufferFactory.Rent(32, isSensitive: true, out Span<byte> key);
        Rfc2898DeriveBytes.Pbkdf2(
            password,
            salt,
            key,
            iterations: 600_000,
            HashAlgorithmName.SHA256
        );

        // The expected MAC lives on the stack and is zeroed when expectedLifetime is disposed.
        Span<byte> expected = stackalloc byte[HMACSHA256.HashSizeInBytes];
        using var expectedLifetime = expected.GetSecureLifetime();
        HMACSHA256.HashData(key, payload, expected);

        // Constant time, so the comparison doesn't reveal where the MACs differ.
        return CryptographicOperations.FixedTimeEquals(expected, signature);
    }
}

Learn more

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 (57)

Showing the top 5 NuGet packages that depend on NCode.Buffers:

Package Downloads
NCode.Extensions.DataProtection

Extensions and utilities for ASP.NET Core Data Protection, including a type-safe factory pattern for creating IDataProtector instances with automatic purpose string derivation, and high-performance span-based protection operations using IBufferWriter.

NCode.Identity.Secrets.AwsKms

AWS KMS key wrapper and remote key provider for NCode.Identity.

NCode.Identity.Secrets.AzureKeyVault

Azure Key Vault key wrapper and remote key provider for NCode.Identity.

NCode.Identity.Jose.EdDsa

Clean-room OKP (RFC 8037) support for NCode.Identity.Jose — an OKP secret-key type, EdDSA (Ed25519 / Ed448, RFC 8032) JWS signatures, and ECDH-ES key agreement over X25519 / X448 (RFC 7748), with no third-party cryptographic dependency.

NCode.Identity.Cose.Abstractions

Contracts of CBOR Object Signing and Encryption (COSE, RFC 9052 / 9053) for NCode.Identity: the labels and values of COSE maps, the algorithm, key type and curve vocabularies as registered data, the COSE_Key converter and the COSE serializer.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
5.0.1 0 11/15/2026
5.0.0 0 11/15/2026
4.1.0 2,697 1/21/2026
4.0.0 168 1/17/2026