public static void Equivalence_Hmac(HashAlgorithmName algorithm, bool useSecretAgreementAsHmac, bool prepend, bool append) { using (ECDiffieHellmanCng ecdh = NewDefaultECDHCng()) using (ECDiffieHellmanPublicKey publicKey = ecdh.PublicKey) { byte[] secretPrepend = prepend ? new byte[3] : null; byte[] secretAppend = append ? new byte[4] : null; byte[] hmacKey = useSecretAgreementAsHmac ? null : new byte[12]; byte[] newWay = ecdh.DeriveKeyFromHmac(publicKey, algorithm, hmacKey, secretPrepend, secretAppend); ecdh.HashAlgorithm = new CngAlgorithm(algorithm.Name); ecdh.HmacKey = hmacKey; ecdh.SecretPrepend = secretPrepend; ecdh.SecretAppend = secretAppend; ecdh.KeyDerivationFunction = ECDiffieHellmanKeyDerivationFunction.Hmac; byte[] oldWay = ecdh.DeriveKeyMaterial(publicKey); Assert.Equal(newWay, oldWay); } }