using WvdS.System.Security.Cryptography;
using WvdS.System.Security.Cryptography.KeyExchange;
using WvdS.System.Security.Cryptography.Encryption;
// 1. Configurazione
CryptoConfig.DefaultMode = CryptoMode.Hybrid;
// 2. Scambio chiavi
using var mlKem = MlKem.Create(MlKemParameterSet.MlKem768);
byte[] publicKey = mlKem.ExportPublicKey();
// Mittente: Encapsulate
var encap = MlKem.Encapsulate(publicKey);
byte[] ciphertext = encap.Ciphertext;
byte[] senderSecret = encap.SharedSecret;
// Destinatario: Decapsulate
byte[] receiverSecret = mlKem.Decapsulate(ciphertext);
// 3. Derivazione chiavi
byte[] aesKey = KeyDerivationExtensions.DeriveKey(
receiverSecret,
outputLength: 32,
info: Encoding.UTF8.GetBytes("AES-256-GCM"));
// 4. Cifratura
var aes = new Aes256Gcm(aesKey);
byte[] encrypted = aes.Encrypt(plaintext);
byte[] decrypted = aes.Decrypt(encrypted);