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 |
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; | |
| byte[] data = "critical firmware update"u8.ToArray(); | |
| // Generate SLH-DSA key | |
| using var signingKey = SLHDSA.GenerateKey(SLHDSAAlgorithm.SLHDSA128S); | |
| // Sign the data | |
| byte[] signature = signingKey.SignData(data); |
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.Net.Http; | |
| using var client = new HttpClient(); | |
| string html = await client.GetStringAsync("https://example.com"); // Uses TLS 1.3 on macOS automatically |
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.Net.WebSockets; | |
| using System.IO; | |
| // Client side, streaming supported over WebSockets | |
| var client = new ClientWebSocket(); | |
| await client.ConnectAsync(new Uri("wss://example.com/upload"), CancellationToken.None); | |
| using var wsStream = WebSocketStream.Create(client); | |
| await using var fileStream = File.OpenRead("bigfile.zip"); |
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; | |
| byte[] data = "hello PQC"u8.ToArray(); | |
| // 1) Generate a post-quantum signature key (ML-DSA) | |
| using var signingKey = MLDSA.GenerateKey(MLDSAAlgorithm.MLDSA65); | |
| // 2) Sign the data | |
| byte[] signature = signingKey.SignData(data); |
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.IO; | |
| using System.IO.Compression; | |
| using System.Threading; | |
| using System.Threading.Tasks; | |
| public static class ZipExtractor | |
| { | |
| public static async Task ExtractZipAsync( | |
| string zipPath, |
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.IO; | |
| using System.IO.Compression; | |
| using System.Text; | |
| using System.Threading.Tasks; | |
| async Task ReadConcatenatedGzipAsync(string path) | |
| { | |
| await using var fileStream = File.OpenRead(path); | |
| await using var gzip = new GZipStream(fileStream, CompressionMode.Decompress); |
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.IO.Pipelines; | |
| var pipe = new Pipe(); | |
| _ = Task.Run(async () => | |
| { | |
| try | |
| { | |
| await JsonSerializer.SerializeAsync(pipe.Writer, new Person("Alice")); | |
| await pipe.Writer.FlushAsync(); | |
| } |
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.IO.Pipelines; | |
| using System.Text.Json; | |
| // Produce JSON into a pipeline | |
| var pipe = new Pipe(); | |
| _ = Task.Run(async () => | |
| { | |
| await JsonSerializer.SerializeAsync(pipe.Writer, new Person("Alice")); | |
| await pipe.Writer.CompleteAsync(); | |
| }); |
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.Text.Json; | |
| // Payload with a duplicated "Value" key | |
| string json = "{ \"Value\": 1, \"Value\": -1 }"; | |
| var options = new JsonSerializerOptions | |
| { | |
| // Reject duplicates option | |
| AllowDuplicateProperties = false | |
| }; |
NewerOlder