Covers digital signatures and X.509 in .NET: certificate fields, chain building and revocation, signing documents and tokens with certificate keys, X509Chain validation, and the move to X509CertificateLoader (SYSLIB0057) in .NET 9 and later.
A digital signature is a hash of the data transformed with a private key; anyone with the matching public key can verify the data is unchanged and came from the key holder. An X.509 certificate answers "whose public key is this?": it binds a public key to a subject (and SAN names), with validity dates and key usages, and is itself signed by a CA. Verifying means building a chain from the leaf through intermediates to a trusted root, checking dates, EKU, name and revocation.
In .NET you sign with cert.GetECDsaPrivateKey() or GetRSAPrivateKey() and validate with X509Chain. Since .NET 9, load certificates with X509CertificateLoader (LoadCertificate, LoadPkcs12): the old X509Certificate2 constructors are obsolete (SYSLIB0057) because they guessed the format from content. The trade-off: PKI gives verifiable identity at the cost of lifecycle management.
"A signature gives integrity and authenticity: I hash the data and sign the hash with my private key, and the verifier checks it with my public key. The problem is trust in the public key itself, and that's what X.509 solves. A certificate says 'this public key belongs to
api.contoso.com.au', with a validity period, key usage and extended key usage like server authentication or code signing, and it's signed by a certificate authority. The CA's certificate is signed by another, up to a root the operating system or my configuration already trusts.Validation is more than checking a signature.
X509Chain.Buildwalks leaf to intermediate to root, checks each signature, the dates, the EKU and the revocation status through CRL or OCSP, and the caller still has to check the name. For internal PKI I setChainPolicy.TrustMode = CustomRootTrustand add our root toCustomTrustStoreinstead of installing it machine-wide.In code, signing a document or a token with a certificate is
cert.GetECDsaPrivateKey().SignData(...), and verification uses the public key from the certificate after the chain is validated. Since .NET 9, I load certificates withX509CertificateLoader.LoadCertificateFromFileorLoadPkcs12FromFile. The old constructors sniffed the content and would happily load PFX, PEM, DER or even PKCS#7, which meant an API expecting a public certificate could end up parsing a PFX with a private key and touching the key store. The loader makes the format explicit and applies PKCS#12 limits.The mistake I see is a
ServerCertificateCustomValidationCallbackthat returnstrueto 'fix' a dev error, which then ships to production and disables TLS authentication completely."
| Field | Meaning |
|---|---|
| Subject / SAN | Who it identifies; browsers and .NET match the hostname against the SAN |
| Issuer | The CA that signed it |
| Validity | NotBefore / NotAfter |
| Public key | RSA or EC key |
| Key usage / EKU | digitalSignature, serverAuth, clientAuth, codeSigning |
| Serial, extensions | Revocation pointers (CRL distribution point, OCSP via AIA) |
| Signature | The CA's signature over all of the above |
| Check | Failure in .NET (X509ChainStatusFlags) |
|---|---|
| Signature chain to a trusted root | UntrustedRoot, PartialChain |
| Dates | NotTimeValid |
| Revocation | Revoked, RevocationStatusUnknown |
| Usage | NotValidForUsage |
| Name | Not checked by X509Chain; TLS stack or your code must check it |
| Old | New |
|---|---|
new X509Certificate2(path) (PEM/DER) |
X509CertificateLoader.LoadCertificateFromFile(path) |
new X509Certificate2(pfxPath, password) |
X509CertificateLoader.LoadPkcs12FromFile(pfxPath, password) |
new X509Certificate2(bytes) |
X509CertificateLoader.LoadCertificate(bytes) |
| PEM with key | X509Certificate2.CreateFromPemFile(certPath, keyPath) |
We signed [PDF statements] for [a lender] with an HSM-backed certificate in Key Vault: the app hashes each document and calls Key Vault Sign, so the private key never leaves the HSM. [About 40,000] statements a night signed in [under 15 minutes], with Key Vault throttling as the limit, not CPU.
Checks understanding of how signatures, certificates and chain validation fit together, and current .NET certificate APIs.
Green flags
X509CertificateLoader and why the constructors were obsoletedRed flags
Signer: digest = SHA-256(document)
sig = Sign(privateKey, digest) -> ship (document, sig, certificate)
Verifier: validate certificate chain -> trusted? usage ok? not revoked?
Verify(cert.PublicKey, SHA-256(document), sig)
The certificate is what turns "a valid signature from some key" into "a valid signature from Contoso Pty Ltd".
[ Root CA ] self-signed, in the trust store (or CustomTrustStore)
| signs
[ Intermediate CA ] sent by the server or fetched via AIA
| signs
[ Leaf: api.contoso.com.au ] SAN, EKU serverAuth, 200-day validity
Servers must send intermediates; missing intermediates are the classic "works in the browser, fails in a Linux container" bug, because browsers fetch or cache them while OpenSSL-based clients may not.
CRLs are lists published by the CA; OCSP is an online query; OCSP stapling lets the server include a signed response. RevocationMode.Online costs network calls and can hang when offline, NoCheck is a conscious risk. Shorter certificate lifetimes (public TLS maximum 200 days since March 2026, falling to 47 days by 2029 under CA/Browser Forum ballot SC-081) reduce reliance on revocation.
The X509Certificate2(byte[]) constructor detected the format from content. That allowed surprising behaviour: a PFX loaded where a public cert was expected, private keys written to disk-backed key stores, and expensive or malicious PKCS#12 files (huge iteration counts) parsed by code that never meant to accept them. The loader is explicit per format and enforces Pkcs12LoaderLimits.
X509SigningCredentials or ECDsaSecurityKey with the cert key; publish the cert/key in JWKS with a kid or x5t.SignedXml (XMLDSig) for SAML and legacy integrations.SignedCms for CMS/PKCS#7 detached signatures.CryptographyClient.SignAsync with a digest.CertificateRequest, then validate the leaf with X509Chain and CustomRootTrust.PartialChain.new X509Certificate2(...) calls in a project and fix SYSLIB0057 warnings..cer public certificate.openssl s_client -showcerts.Loading certificates with X509CertificateLoader, validating a chain against a private root, and signing and verifying a document.
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
namespace Documents.Signing;
public sealed class DocumentSigner(X509Certificate2 signingCert)
{
public byte[] Sign(ReadOnlySpan<byte> document)
{
using ECDsa key = signingCert.GetECDsaPrivateKey()
?? throw new InvalidOperationException("Certificate has no ECDSA private key.");
return key.SignData(document, HashAlgorithmName.SHA256);
}
}
public sealed class DocumentVerifier(X509Certificate2 trustedRoot)
{
public bool Verify(byte[] document, byte[] signature, X509Certificate2 signerCert)
{
using var chain = new X509Chain();
chain.ChainPolicy.TrustMode = X509ChainTrustMode.CustomRootTrust; // only our PKI
chain.ChainPolicy.CustomTrustStore.Add(trustedRoot);
chain.ChainPolicy.RevocationMode = X509RevocationMode.Online;
chain.ChainPolicy.ApplicationPolicy.Add(new Oid("1.3.6.1.5.5.7.3.3")); // EKU: code/document signing
if (!chain.Build(signerCert)) return false; // inspect chain.ChainStatus for diagnostics
using ECDsa? publicKey = signerCert.GetECDsaPublicKey();
return publicKey is not null && publicKey.VerifyData(document, signature, HashAlgorithmName.SHA256);
}
}
public static class CertificateLoading
{
// .NET 9+: explicit formats instead of the obsolete constructors (SYSLIB0057).
public static X509Certificate2 LoadRoot(string path) =>
X509CertificateLoader.LoadCertificateFromFile(path); // .cer / .crt (DER or PEM)
public static X509Certificate2 LoadSigner(string pfxPath, string password) =>
X509CertificateLoader.LoadPkcs12FromFile(pfxPath, password,
X509KeyStorageFlags.EphemeralKeySet); // avoid persisting the key
}
ServerCertificateCustomValidationCallback = (_, _, _, _) => true. Why it is wrong: it removes the only thing proving who you are talking to, so anyone on the path can intercept, read and alter traffic, including credentials and tokens, and the client will never notice. Instead: fix the chain, or trust a specific private root with CustomRootTrust.CustomTrustStore in the handler that needs it.new X509Certificate2(bytes) in .NET 9+. Why it is wrong: format sniffing may parse unexpected PKCS#12 content and the API is obsolete. Instead: X509CertificateLoader.EphemeralKeySet or keys in Key Vault.PartialChain errors. Instead: deploy the full chain.Certificates are an identity system with a lifecycle, and most incidents are lifecycle failures: expiry, missing intermediates, a rotated root nobody distributed. So the senior concerns are where the private key lives (non-exportable in Key Vault or an HSM), how renewal is automated, and how verifiers learn the new key (JWKS with key ids, overlapping validity).
| Option | When it fits | Cost | When not |
|---|---|---|---|
| Public CA certificate | Internet-facing TLS | Automated renewal needed (200-day max now) | Internal service identity |
| Private CA (AD CS, Key Vault + CA integration) | Internal mTLS, document signing | Running a PKI | Public browser trust |
| Raw key pair with JWKS | Token signing | Key publication | When verifiers expect certificates |
| Key Vault HSM signing | High-value signatures | Latency, throttling | Very high-throughput signing |
Measure: days to expiry for every certificate, chain validation failures by status flag, and signing latency if keys are remote.
HTTPS is HTTP inside TLS. TLS gives confidentiality (encryption), integrity (tamper detection) and server authentication (certificates).
TLS 1.3 handshake (one round trip): the client sends supported ciphers, a key share, SNI (hostname) and ALPN (h2); the server replies with its key share, certificate chain and a signature proving it owns the private key. Both derive session keys via ECDHE (forward secrecy).
The client validates: chain to a trusted root, not expired, hostname matches the SAN, and optionally revocation.
For "remote certificate is invalid": read the SslPolicyErrors / chain status, inspect with openssl s_client -showcerts, then fix the real cause (expired cert, missing intermediate, wrong hostname, or a private/corporate root CA not trusted in the container). Never return true from ServerCertificateCustomValidationCallback in production.
Asymmetric cryptography uses a key pair: what one key does, only the other undoes. For encryption you use the recipient's public key and only their private key decrypts. For signing you use your private key and anyone verifies with your public key, proving origin and integrity.
RSA does both: use 3072-bit keys for anything new or long-lived (2048 is only the legacy floor), OAEP-SHA256 for encryption and PSS for new signature formats. ECDSA (signing) and ECDH (key agreement) on P-256/P-384 give equivalent security with much smaller keys. Asymmetric operations are slow and RSA can only encrypt a few hundred bytes, so real systems use hybrid encryption: asymmetric to agree or wrap an AES key, AES for the data, as in TLS and Key Vault key wrapping. Keep private keys non-exportable in Key Vault/HSMs, and plan for post-quantum algorithms (ML-KEM, ML-DSA in .NET 10): ASD's guidance is to move off RSA and ECC by 2030.
How to tell it (STAR)
**S:** At [company] our [claims service] stopped reaching [a partner's API] the morning after they renewed their certificate. **T:** I needed to restore the integration quickly without weakening TLS. **A:** I reproduced the error from a debug pod with `openssl s_client`, saw the partner was sending only the leaf, and confirmed Windows hid the problem by fetching the intermediate through AIA. I scoped the intermediate into a custom trust store on that one named client, kept full validation, and raised a ticket with the partner. **R:** Service was restored in [about 90 minutes], the partner fixed their chain within [a week], and our new Linux-based synthetic check has since caught [two] similar partner issues before users did.
Last updated 23 Nov 2026.