static void Main(string[] args) { Write("Enter some text you want to encrypt and send somebody: "); string message = ReadLine(); using (ECDiffieHellmanCng ecd = new ECDiffieHellmanCng()) { ecd.KeyDerivationFunction = ECDiffieHellmanKeyDerivationFunction.Hash; ecd.HashAlgorithm = CngAlgorithm.Sha256; Person1PublicKey = ecd.PublicKey.ToByteArray(); Person2 person2 = new Person2(); CngKey k = CngKey.Import(person2.Person2PublicKey, CngKeyBlobFormat.EccPublicBlob); byte[] senderKey = ecd.DeriveKeyMaterial(CngKey.Import(person2.Person2PublicKey, CngKeyBlobFormat.EccPublicBlob)); Send(senderKey, message, out byte[] encryptedMessage, out byte[] IV); person2.Receive(encryptedMessage, IV); } }