public void AuthenticatedSymmetricAlgorithmVerifierTestNegativeStandardEncryptAuthenticatedDecryptTest() { byte[] plaintext = Encoding.UTF8.GetBytes("Plaintext"); byte[] ciphertext = null; byte[] key = null; SymmetricEncryptionState encryptionState = null; using (SymmetricAlgorithm encryptAes = new AesCng().EnableLogging()) { key = encryptAes.Key; using (MemoryStream ms = new MemoryStream()) using (CryptoStream cs = new CryptoStream(ms, encryptAes.CreateEncryptor(), CryptoStreamMode.Write)) { cs.Write(plaintext, 0, plaintext.Length); cs.FlushFinalBlock(); ciphertext = ms.ToArray(); encryptionState = encryptAes.GetLastEncryptionState(); } } using (SymmetricAlgorithm decryptAes = (new AuthenticatedAesCng() as SymmetricAlgorithm).EnableDecryptionVerification(encryptionState)) { decryptAes.Key = key; decryptAes.IV = new byte[] { 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }; using (MemoryStream ms = new MemoryStream()) using (CryptoStream cs = new CryptoStream(ms, decryptAes.CreateDecryptor(), CryptoStreamMode.Write)) { cs.Write(ciphertext, 0, ciphertext.Length); cs.FlushFinalBlock(); } } Assert.Fail("Decryption should have failed."); }