KeyWarden.Sdk 1.2.2

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

KeyWarden.Sdk

The official .NET client for Key-Warden. Validate a software licence online — seat-aware, revocation-aware — or verify a signed token offline against your embedded public key, with no network round-trip.

Targets net8.0 and netstandard2.0 (so it runs on .NET Framework 4.6.1+, .NET Core, .NET 5–8, Xamarin, Unity). Ed25519 verification is provided by BouncyCastle.Cryptography.

dotnet add package KeyWarden.Sdk

Validate online

The authoritative check. Ask the platform whether a licence is good right now.

using KeyWarden;

var res = await KeyWardenClient.ValidateAsync(customerLicenceKey, new ValidateOptions
{
    ApimKey   = Environment.GetEnvironmentVariable("KW_APIM_KEY"),   // your APIM subscription key
    ClientKey = Environment.GetEnvironmentVariable("KW_CLIENT_KEY"), // your validation key
    MachineId = KeyWardenClient.MachineIdFrom(Environment.MachineName, userId), // stable, hashed your side
});

if (!res.Valid) throw new Exception($"licence not valid: {res.Reason}");
// res.Token is a freshly signed proof - cache it for the offline path below.

A Valid == false (e.g. revoked, expired, seat_limit_exceeded) is data, not an exception. A wrong ClientKey throws a KeyWardenError with Code == "unauthorized_client" — that's your auth failing, and your customer should never see it as a licence problem.

Verify offline

No connection? Verify a token you already hold against your public key — the 32-byte raw key from your vendor console. Pure and synchronous.

var check = KeyWardenClient.VerifyToken(cachedToken, publicKeyBase64);
if (!check.Valid) LockFeatures(check.Reason); // "bad_signature" | "expired" | ...

The token is header.body.signature (compact JWT style) and the Ed25519 signature covers the exact bytes header.body. This client verifies over those bytes — it never decodes-then-reverifies, which is the one mistake that silently breaks offline checks. Expiry is honoured within the offline grace window you set at mint time.

Online, with an offline fallback

The pattern most desktop apps want: online is authoritative; if the network is down, keep working within grace.

var res = await KeyWardenClient.ValidateOrVerifyAsync(customerLicenceKey, new ValidateOrVerifyOptions
{
    ApimKey = apimKey, ClientKey = clientKey, MachineId = machineId,
    CachedToken = lastGoodToken,   // from a previous ValidateAsync
    PublicKey   = publicKeyBase64,
});
// res.Source == "online" | "offline"

A rejected ClientKey (401) is never masked by the offline path — only a genuine reachability failure falls back.

API

Member Purpose
ValidateAsync(key, ValidateOptions) Online check. Returns ValidateResult { Valid, Reason?, ActiveSeats?, Token? }.
VerifyToken(token, rawPubB64, now?) Offline check. Returns VerifyResult { Valid, Reason?, Claims? }.
ValidateOrVerifyAsync(key, ValidateOrVerifyOptions) Online, falling back to a cached token when unreachable.
MachineIdFrom(params string[]) A stable SHA-256 machine id; raw parts never leave the machine.

Any real failure (bad credentials, unreachable gateway, server error) throws KeyWardenError, which carries .Code and .Status.

Verify the build yourself

The repository ships a console self-test that mints tokens exactly the way the platform signs them, then runs the same 16 checks used to certify the Node and Python clients:

dotnet run --project selftest/KeyWarden.Sdk.SelfTest
#   16 passed, 0 failed

Security notes

  • Your private signing key never leaves Key-Warden's Key Vault. You embed only the 32-byte public half.
  • MachineId is hashed by the platform, but send an opaque, stable id — not a raw MAC address or a hostname you wouldn't want logged. MachineIdFrom() hashes on your side too.
  • Two independent credentials gate every online call: the APIM subscription key gets you to the gateway, the validation key authenticates you as the vendor. A leaked validation key can be rotated without reissuing a single customer licence.

Code protection (Seal / Unlock / Unseal)

Lock part of your product so it only runs for a valid, activated licence. Get your content key (base64) from the vendor console → Protect your code.

// Build time — seal a file once:
var blob = KeyWardenClient.Seal(File.ReadAllBytes("secret.dll"), MyContentKeyBase64);
File.WriteAllText("secret.sealed", blob);   // ship this instead

// Runtime — the key rides in the validate token as `ck`, machine-bound:
var res  = await KeyWardenClient.ValidateAsync(licence,
             new ValidateOptions { ApimKey = apim, ClientKey = ck, MachineId = mid });
byte[] key  = KeyWardenClient.UnlockFromToken(res.Token, mid);   // content key
byte[] code = KeyWardenClient.Unseal(sealedBlob, key);           // decrypted bytes

// Or a live check every time (real-time revocation):
byte[] key2 = await KeyWardenClient.UnsealOnlineAsync(licence,
                new UnsealOptions { ApimKey = apim, MachineId = mid });

All AES-256-GCM. Unlock needs the SAME MachineId you validate with. A revoked licence stops getting the key.

Licence

MIT.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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.5.2 106 9/14/2026
1.5.1 101 9/14/2026
1.3.0 124 8/23/2026
1.2.2 117 8/22/2026
1.2.1 117 8/22/2026
1.0.6 113 8/12/2026
1.0.0 114 8/12/2026