Security

Cryptography & Key Management

Intermediate

Cryptography is easy to call and hard to get right. The algorithms are rarely the weak point. How you handle the keys around them almost always is. Use proven primitives through proven libraries, and focus your attention on where keys live, how they rotate, and who can reach them.

The rule that helps most often is the simplest: do not invent it. Use checked, standard, well-maintained libraries for hashing, encryption, signing, and randomness, and use them in the way they are meant to be used. Then protect keys carefully, because an algorithm is only as strong as the secrecy and lifecycle of its key.

The Finperiti sample is a warning: one shared symmetric (HS256) JWT secret used across all tenants. With a shared symmetric secret, anyone who can verify a token can also forge one, and a single leak compromises everyone. Asymmetric signing and per-scope keys exist to limit that blast radius.

Use proven crypto correctly

Manage keys like crown jewels

Shared symmetric token secret // appsettings.json, same value in every environment
"Jwt": { "Secret": "super-secret-shared-key" }

Anyone who can validate a token can also forge one, and one leak breaks every tenant. Move to asymmetric keys (private key in the vault) and verify with the public key.

Vault-held signing key var key = await keyVault.GetKeyAsync("jwt-signing", version);
// sign with the private key in the vault; clients verify with the public key

The signing key never leaves the vault, rotates by version, and a leaked verification key cannot be used to forge.

Self-review checklist

Why it matters: Broken cryptography rarely fails loudly. It works perfectly while quietly giving no protection. Because we hold biometric and special-category data, a key-management failure is not a small problem. It is a reportable breach of the most sensitive data we touch. Proven primitives plus disciplined key handling is what matters most.