Bitwarden.Server.Sdk.CryptoPrimitives 0.2.0

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

Bitwarden.Server.Sdk.CryptoPrimitives

About

Cryptographic primitives built only on System.Security.Cryptography.

Installing

dotnet add package Bitwarden.Server.Sdk.CryptoPrimitives

Usage

Derive a cache key

Derive a 32-byte cache key from a secret and a list of strings:

var secret = CacheSecret.FromString(configuration["Caching:Secret"]!);  // base64, 32 bytes
var key = CacheKey.DeriveCacheKey(secret, "account-by-email", email);
var redisKey = key.ToString();  // base64

The key is HMAC-SHA-256(secret, LP(p0) || ... || LP(pn)), where LP(x) = uint64_be(len(utf8(x))) || utf8(x). The length prefixes keep ("ab", "c") and ("a", "bc") apart.

CacheSecret.Development is 32 zero bytes, the same as default. Use it only in development: anyone can derive the same keys from it.

Gotchas and constraints

  • A parameter that is not valid UTF-16, such as a lone surrogate, throws EncoderFallbackException rather than being replaced and colliding with another string.
  • FromString reads base64 for both types. A CacheKey writes it with ToString(). A CacheSecret's ToString() returns a fixed marker, never the secret, so logging one gives nothing away; ToBase64() writes the secret itself, only for storing it where secrets are kept.

Types

Type Purpose
CacheSecret The 32-byte secret cache keys are derived from
CacheKey A 32-byte cache key derived from a secret
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.
  • net10.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Bitwarden.Server.Sdk.CryptoPrimitives:

Package Downloads
Bitwarden.Server.Sdk.Resources.Caching.Abstractions

How a Bitwarden service-owned cache entry is stored and keyed, shared by its owner and its readers.

Bitwarden.Server.Sdk.Idempotency.Abstractions

Idempotency keys, and the operations whose writes repeat the same keys, shared by Bitwarden services and their callers.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.0 283 12/5/2026
0.1.0 8,896 11/13/2026