Skip to content

Instantly share code, notes, and snippets.

View AnthonyGiretti's full-sized avatar
💭
👍

[MVP] Anthony Giretti AnthonyGiretti

💭
👍
View GitHub Profile
@AnthonyGiretti
AnthonyGiretti / Program.cs
Last active January 19, 2026 01:44
.NET 10 Post Quantum Cryptography, example with ML-KEM
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
@AnthonyGiretti
AnthonyGiretti / Program.cs
Created January 19, 2026 01:40
.NET 10 Post Quantum Cryptography, example with SLH-DSA
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);
@AnthonyGiretti
AnthonyGiretti / Program.cs
Created January 7, 2026 20:18
.NET 10 , automatic support of TLS 1.3 on macOS
using System.Net.Http;
using var client = new HttpClient();
string html = await client.GetStringAsync("https://example.com"); // Uses TLS 1.3 on macOS automatically
@AnthonyGiretti
AnthonyGiretti / Program.cs
Created January 7, 2026 20:18
.NET 10 new WebSocketStream API
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");
@AnthonyGiretti
AnthonyGiretti / Program.cs
Created January 7, 2026 20:10
.NET 10 Post Quantum cryptography; exemple with ML-DSA signature algo
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);
@AnthonyGiretti
AnthonyGiretti / Program.cs
Created January 7, 2026 20:08
.NET 10 ZipExtractor better async performances
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,
@AnthonyGiretti
AnthonyGiretti / Program.cs
Created January 7, 2026 20:07
.NET 10 GZip concatenated read + better performance
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);
@AnthonyGiretti
AnthonyGiretti / Program.cs
Last active January 7, 2026 20:02
Before .NET 10 System.Text.Json and deserilization from Stream
using System.IO.Pipelines;
var pipe = new Pipe();
_ = Task.Run(async () =>
{
try
{
await JsonSerializer.SerializeAsync(pipe.Writer, new Person("Alice"));
await pipe.Writer.FlushAsync();
}
@AnthonyGiretti
AnthonyGiretti / Program.cs
Created January 7, 2026 19:47
.NET 10 System.Text.Json and PipeReader support
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();
});
@AnthonyGiretti
AnthonyGiretti / Program.cs
Created January 7, 2026 19:44
.NET 10 System.Text.Json duplicates rejection
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
};