A bound device key fixes the oldest hole in node-locking: you can copy a license file to a second machine, but you cannot copy the private key it demands a signature from, so the copy fails the challenge. That holds right up until someone reads the key off disk. A software key — even one in DPAPI-protected per-user storage — is a sequence of bytes in a file. Code running as that user can decrypt it, lift it, and clone the device onto a hundred others. Proof-of-possession has moved the attack from "copy a file" to "extract a key," which is progress, but on a compromised machine the key is still extractable.
The real question
A TPM changes the shape of the answer. The question is no longer where do I hide the key so it is hard to read? but can I create a key that cannot be read at all — even by code running as the owner — and can I prove to my server that this is such a key? Those are two distinct claims, and they need two distinct mechanisms. The first is a non-exportable, hardware-resident key: generated inside the TPM, usable for signing, never readable out. The second is key attestation: a signed statement from the chip that the key really is TPM-resident and non-exportable, so the server does not have to take the client's word for it.
Create the key inside the TPM
On Windows, CNG exposes the TPM through a named provider: the Microsoft Platform Crypto Provider. A key created against that provider has its private half generated and held by the chip. Setting ExportPolicy to None makes it non-exportable, so there is no API that will ever hand the private key back as bytes.
using System.Security.Cryptography;
const string KeyName = "keyright-device-key";
CngProvider tpm = CngProvider.MicrosoftPlatformCryptoProvider;
if (!CngKey.Exists(KeyName, tpm))
{
var creationParams = new CngKeyCreationParameters
{
Provider = tpm, // route key material to the TPM
KeyCreationOptions = CngKeyCreationOptions.None, // per-user key
ExportPolicy = CngExportPolicies.None, // private key can never be exported
};
// The key pair is generated by the chip; the private half stays inside it.
using CngKey created = CngKey.Create(CngAlgorithm.ECDsaP256, KeyName, creationParams);
}
What leaves the machine at activation is only the public key, and exporting that is always allowed — the non-exportable policy covers the private half only:
using CngKey key = CngKey.Open(KeyName, tpm);
using var ecdsa = new ECDsaCng(key);
byte[] spki = ecdsa.ExportSubjectPublicKeyInfo(); // public key only — safe to send
The issuing service binds that public key into the signed license exactly as it would a software device key — it is a claim covered by the vendor signature. Nothing about the binding changes. What changes is the guarantee behind the private half: it is not in a file, not in the registry, not in your process — it is in the chip.
Prove possession by signing a challenge
Possession works the same way it does for a software key, because from the caller's side signing is just SignData. The difference is underneath: ECDsaCng does not pull the key into managed memory and sign in software — it cannot, the bytes are not available — it passes the hash to the chip and the chip returns the signature.
// Server: a fresh, single-use, short-lived challenge.
byte[] challenge = RandomNumberGenerator.GetBytes(32);
// Client: the TPM signs; the private key never enters process memory.
using CngKey key = CngKey.Open(KeyName, CngProvider.MicrosoftPlatformCryptoProvider);
using var ecdsa = new ECDsaCng(key);
byte[] proof = ecdsa.SignData(challenge, HashAlgorithmName.SHA256);
It is worth looking at the IL, because it shows that the TPM routing is not magic — it is a provider selection resolved at a specific call site. Decompile the signing method and the operative instructions are the provider lookup and the virtual dispatch into the CNG implementation:
.method private hidebysig static uint8[] Sign (uint8[] challenge) cil managed
{
.maxstack 3
.locals init (
[0] class [System.Security.Cryptography]System.Security.Cryptography.CngKey key,
[1] class [System.Security.Cryptography]System.Security.Cryptography.ECDsaCng ecdsa)
IL_0000: ldstr "keyright-device-key"
IL_0005: call class [System.Security.Cryptography]System.Security.Cryptography.CngProvider [System.Security.Cryptography]System.Security.Cryptography.CngProvider::get_MicrosoftPlatformCryptoProvider()
IL_000a: call class [System.Security.Cryptography]System.Security.Cryptography.CngKey [System.Security.Cryptography]System.Security.Cryptography.CngKey::Open(string, class [System.Security.Cryptography]System.Security.Cryptography.CngProvider)
IL_000f: stloc.0
IL_0010: ldloc.0
IL_0011: newobj instance void [System.Security.Cryptography]System.Security.Cryptography.ECDsaCng::.ctor(class [System.Security.Cryptography]System.Security.Cryptography.CngKey)
IL_0016: stloc.1
IL_0017: ldloc.1
IL_0018: ldarg.0
IL_0019: call valuetype [System.Security.Cryptography]System.Security.Cryptography.HashAlgorithmName [System.Security.Cryptography]System.Security.Cryptography.HashAlgorithmName::get_SHA256()
IL_001e: callvirt instance uint8[] [System.Security.Cryptography]System.Security.Cryptography.ECDsa::SignData(uint8[], valuetype [System.Security.Cryptography]System.Security.Cryptography.HashAlgorithmName)
IL_0023: ret
}
The call … get_MicrosoftPlatformCryptoProvider() is the hinge. Swap it for CngProvider.MicrosoftSoftwareKeyStorageProvider and the identical managed code signs with a software key instead — same SignData, same callvirt, entirely different security property. The callvirt to ECDsa.SignData dispatches to the ECDsaCng override, which marshals the hash into NCrypt and ultimately TPM2_Sign. The private key is never an operand of any instruction here; it is a handle the chip dereferences on its own side of the boundary.
Attestation: proving the key is really in the TPM
Possession has a blind spot. A perfectly honest signature over the challenge proves the caller holds the private key — it says nothing about where that key lives. A client could create an ordinary software key with MicrosoftSoftwareKeyStorageProvider, prove possession flawlessly, and the server could not tell the difference. If your goal is only to defeat file copying, that is fine. If your goal is to insist the key is genuinely non-exportable, you need the chip to vouch for it.
That is what TPM key attestation does. The TPM produces a signed statement — a claim — that a given subject key is resident in the TPM and was created non-exportable, signed under the chip's attestation identity key, which itself chains to the TPM's endorsement key. The server verifies that chain and gains assurance the key it bound is a hardware key, not a software impostor.
Be honest about the boundary here: the BCL does not expose key attestation. CngKey lets you create, open, sign and read properties, but there is no managed API that produces an attestation claim. For that you drop to NCrypt via P/Invoke — NCryptCreateClaim with the platform claim type — and verify the resulting blob server-side:
using Microsoft.Win32.SafeHandles;
using System.Runtime.InteropServices;
// Outside the BCL: NCrypt key attestation (ncrypt.dll). There is no managed
// CngKey API for this — the signature below is simplified for illustration.
internal static partial class NCrypt
{
internal const uint NCRYPT_CLAIM_PLATFORM = 0x00010000;
[LibraryImport("ncrypt.dll")]
internal static partial int NCryptCreateClaim(
SafeNCryptKeyHandle hSubjectKey,
SafeNCryptKeyHandle hAuthorityKey, // the attestation identity key
uint dwClaimType, // NCRYPT_CLAIM_PLATFORM
IntPtr pParameterList,
byte[]? pbClaimBlob,
uint cbClaimBlob,
out uint pcbResult,
uint dwFlags);
}
// The subject key's native handle comes from the CngKey you already created:
using CngKey key = CngKey.Open("keyright-device-key", CngProvider.MicrosoftPlatformCryptoProvider);
SafeNCryptKeyHandle subject = key.Handle; // feeds hSubjectKey above
The claim blob travels with the activation request alongside the public key and the possession proof. The server validates the claim's signature up to a trusted attestation authority, confirms it describes the same public key being bound, and only then marks the binding as hardware-backed. This is real work — provisioning the attestation identity key and validating the chain is the bulk of the effort — which is exactly why possession and attestation are kept as separate layers: most vendors want the file-copy defense immediately and add hardware attestation where the threat justifies it.
When it still breaks
The honest caveats start with availability. Not every machine has a usable TPM: VMs, older hardware and some locked-down images either have none or expose a virtual TPM. CngKey.Create against the Platform Crypto Provider throws when there is no usable chip, so hardware binding must be a path you fall back from, never an assumption. A virtual TPM still yields a key that is non-exportable from inside the guest — useful against in-guest extraction — but its attestation names a software TPM, and you decide whether that clears your bar.
Then there is the platform wall. Everything above is Windows/CNG. CngKey, the Platform Crypto Provider and ECDsaCng throw PlatformNotSupportedException off Windows. A TPM on Linux is reached through tpm2-tss or the kernel resource manager; the macOS analogue is the Secure Enclave through the Security framework — both outside the BCL. The portable design detects a hardware key store on Windows, falls back to an OS-protected software key elsewhere, and records which kind of key each activation used so the server applies the right trust level rather than pretending every device offers a hardware root.
Finally, a TPM is not a DRM silver bullet. It protects the key from extraction; it does not protect the decision the key gates. A patched client that signs the challenge honestly and then ignores the IsValid result has defeated nothing cryptographic — it has defeated your control flow. Hardware key binding belongs with fail-closed enforcement and, for distributed binaries, obfuscation of the verification path so the check cannot simply be branched around. Nebula.NET covers that side; see Nebula.NET.
Takeaway
A software device key stops the license file from being copied. A TPM-protected key stops the key itself from being copied, by making it a capability the chip exercises on request but never surrenders as bytes. Create it in the Microsoft Platform Crypto Provider with ExportPolicy.None, bind the public half into the signed license, and prove possession by signing a fresh challenge — all in the BCL on Windows. Add key attestation, through NCrypt, when you need the server to know the key is hardware-resident and not a software stand-in. Be straight with yourself about the limits: Windows-only through the BCL, a real fallback when no TPM exists, and enforcement that still has to hold after the signature checks out.
Keyright is a self-hosted .NET licensing system — an issuing service plus SDK — with a free Community Edition. Device binding and the activation handshake are covered in the Keyright docs; for the software-key primitive this hardens, see proof-of-possession device binding, and for the hardware-hash approach it complements, machine fingerprinting and hardware drift.
Top comments (1)
Clear explanation of why "non-exportable" and "attested" are two separate claims. A few operational things worth planning before shipping this: