Riferimento rapido
Esempi di codice compatti per iniziare rapidamente. Per spiegazioni dettagliate vedere gli scenari collegati.
PKI e certificati
Firme
Scambio chiavi e cifratura
Import/Export
Avvio rapido: Workflow completo
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);
Approfondimenti
Wolfgang van der Stille @ EMSR DATA d.o.o. - Post-Quantum Cryptography Professional