# Post-quantum TLS in .NET: SslStream, Kestrel, OpenSSL 3.5 and the MLKem class

> .NET uses the OS TLS stack, so post-quantum TLS depends on OpenSSL 3.5+ on Linux or SChannel on Windows. Check your image, fix configs, and use .NET 10's MLKem.

Source: https://pqshift.dev/learn/post-quantum-tls-dotnet · Published 2026-12-04 · Updated 2026-12-04 · pqshift

.NET doesn't implement TLS itself. `SslStream`, `HttpClient` and Kestrel use the operating system's TLS stack, so whether they negotiate the hybrid post-quantum group `X25519MLKEM768` depends on the OS. On **Linux**, .NET uses the system OpenSSL, so OpenSSL 3.5+ gives you hybrid key exchange by default. On **Windows** it's SChannel, so it depends on the Windows version. On **macOS**, .NET 10 has no post-quantum support. Separately, .NET 10 adds an `MLKem` class (FIPS 203) for application-level key encapsulation.

## Look at the image, not the .NET version (Linux and containers)

```bash
docker run --rm your-image sh -c 'openssl version; ldconfig -p | grep libssl'
```

.NET loads `libssl` from the image at runtime. The official `mcr.microsoft.com/dotnet/*` images are built on Debian, Ubuntu, Azure Linux and Alpine, and each ships its distribution's OpenSSL. If that is older than 3.5, `SslStream` can't offer the hybrid group, whatever the .NET version. Move to a base image whose distribution ships OpenSSL 3.5+, or build OpenSSL 3.5 into the image.

## Kestrel and HttpClient

No code changes are needed: with OpenSSL 3.5+ on Linux, Kestrel servers and `HttpClient` both offer `X25519MLKEM768` because it is in OpenSSL's default group list. Things that can switch it off:

- **An OpenSSL config** (`/etc/ssl/openssl.cnf`, `OPENSSL_CONF`) that sets `Groups` or `Curves` to a classical list. Hardened base images sometimes do this. Put `X25519MLKEM768` first:

```ini
# openssl.cnf
[system_default_sect]
Groups = X25519MLKEM768:X25519:P-256:P-384
```

- **TLS 1.2 only.** Hybrid groups exist only in TLS 1.3. Check `SslProtocols` in Kestrel's `ConfigureHttpsDefaults` and in any `SocketsHttpHandler.SslOptions`, and allow TLS 1.3.

## Behind a reverse proxy or a PaaS

If TLS terminates in front of your app, that layer decides. Azure App Service is rolling out `X25519MLKEM768` automatically; Azure Front Door offers it by default; AWS ALBs need a `-PQ-` policy. See [cloud load balancers](https://pqshift.dev/learn/post-quantum-tls-cloud-load-balancers) and [nginx/OpenSSL servers](https://pqshift.dev/learn/post-quantum-tls-nginx).

## ML-KEM in code: the MLKem class (.NET 10)

.NET 10 adds `System.Security.Cryptography.MLKem`. Unlike `MLDsa`, `SlhDsa` and `CompositeMLDsa`, its core methods are not marked experimental. It needs OpenSSL 3.5+ on Linux or a Windows build with CNG post-quantum support, and is not available on macOS. Always check `IsSupported`:

```csharp
using System.Security.Cryptography;

if (!MLKem.IsSupported)
    throw new PlatformNotSupportedException("ML-KEM needs OpenSSL 3.5+ or Windows CNG PQC");

// Receiver: generate a key pair and publish the encapsulation key
using MLKem receiver = MLKem.GenerateKey(MLKemAlgorithm.MLKem768);
byte[] encapsulationKey = receiver.ExportEncapsulationKey();

// Sender: encapsulate against the published key
using MLKem sender = MLKem.ImportEncapsulationKey(MLKemAlgorithm.MLKem768, encapsulationKey);
sender.Encapsulate(out byte[] ciphertext, out byte[] senderSecret);

// Receiver: recover the same 32-byte shared secret
byte[] receiverSecret = receiver.Decapsulate(ciphertext);
```

To replace RSA key wrapping (`RSA.Encrypt` with OAEP) or `ECDiffieHellman`, stay hybrid: combine the ML-KEM secret with an `ECDiffieHellman` (P-256 or X25519) secret through `HKDF.DeriveKey`, and add a version byte to the ciphertext format so data wrapped the old way still decrypts.

## Verify the handshake

```bash
openssl s_client -connect your-app.example:443 -tls1_3 -groups X25519MLKEM768 -brief </dev/null 2>&1 | grep -i group
```

You want `Negotiated TLS1.3 group: X25519MLKEM768`. For a .NET client, connect it to a server that only accepts the hybrid group, as described in [How to check if a server uses post-quantum TLS](https://pqshift.dev/learn/test-post-quantum-tls).

## FAQ

### Does .NET support post-quantum TLS?

Through the operating system. On Linux, .NET uses the system OpenSSL, so OpenSSL 3.5+ negotiates X25519MLKEM768 by default for SslStream, HttpClient and Kestrel. On Windows it depends on SChannel; .NET 10 has no PQC on macOS.

### How do I use ML-KEM in C#?

In .NET 10, MLKem.GenerateKey(MLKemAlgorithm.MLKem768) creates a key pair, Encapsulate(out ciphertext, out secret) runs on the sender, and Decapsulate(ciphertext) on the receiver. Check MLKem.IsSupported first.

## Sources

- [.NET Blog: Post-quantum cryptography in .NET (Nov 2025)](https://devblogs.microsoft.com/dotnet/post-quantum-cryptography-in-dotnet/)
- [Duende: Post-quantum cryptography in .NET 10, a practical guide](https://duendesoftware.com/blog/20260514-post-quantum-cryptography-in-dotnet-10)
- [Post-quantum TLS in .NET 10 on Linux (OpenSSL 3.5 in Docker)](https://dev.to/daan_acohen/post-quantum-tls-in-net-10-on-linux-ml-kem-in-a-real-dockerized-http-client-2lnl)
- [Azure App Service: preparing TLS for post-quantum cryptography (Nov 2026)](https://azure.github.io/AppService/2026/11/09/post-quantum-tls-app-service-azure-functions.html)
