Last active
January 19, 2026 01:44
-
-
Save AnthonyGiretti/eeab1bb3d624f86a1eb68e623bc91004 to your computer and use it in GitHub Desktop.
.NET 10 Post Quantum Cryptography, example with ML-KEM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Security.Cryptography; | |
| // 1) Server generates a KEM key pair | |
| using var serverKey = MLKEM.GenerateKey(MLKEMAlgorithm.MLKEM768); | |
| // Export public key | |
| string serverPublicPem = serverKey.ExportSubjectPublicKeyInfoPem(); | |
| // 2) Client imports public key | |
| using var clientKey = MLKEM.ImportFromPem(serverPublicPem); | |
| // Client encapsulates a shared secret | |
| (byte[] ciphertext, byte[] clientSharedSecret) = clientKey.Encapsulate(); | |
| // 3) Server decapsulates using private key | |
| byte[] serverSharedSecret = serverKey.Decapsulate(ciphertext); / | |
| // 4) Both sides now share the same secret | |
| Console.WriteLine( Convert.ToBase64String(clientSharedSecret) == Convert.ToBase64String(serverSharedSecret) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment