为什么导入这个CngKey? (Diffie-Hellman(ECDH)算法)

时间:2017-03-19 16:16:05

标签: c# algorithm cryptography diffie-hellman

我正在查看Microsoft发现的here为Diffie-Hellman(ECDH)算法实现提供的示例。

为什么要为未使用的变量k分配值?

        using (ECDiffieHellmanCng alice = new ECDiffieHellmanCng())
        {
            alice.KeyDerivationFunction = ECDiffieHellmanKeyDerivationFunction.Hash;
            alice.HashAlgorithm = CngAlgorithm.Sha256;
            alicePublicKey = alice.PublicKey.ToByteArray();
            Bob bob = new Bob();
            CngKey k = CngKey.Import(bob.bobPublicKey, CngKeyBlobFormat.EccPublicBlob);
            byte[] aliceKey = alice.DeriveKeyMaterial(CngKey.Import(bob.bobPublicKey, CngKeyBlobFormat.EccPublicBlob));
            byte[] encryptedMessage = null;
            byte[] iv = null;
            Send(aliceKey, "Secret message", out encryptedMessage, out iv);
            bob.Receive(encryptedMessage, iv);
        }

他们这样做是否有原因?他们只是忘了在下一行使用它吗?

0 个答案:

没有答案