private void CheckVector(byte[] key, byte[] plaintext, byte[] additional, byte[] nonce, byte[] ciphertext, byte[] tag) { BulkCipherAlgorithmAesGcm cipher = new BulkCipherAlgorithmAesGcm(key.Length * 8, tag.Length * 8); ICryptoTransform encryptor = cipher.CreateEncryptor(key, nonce, additional); byte[] enc = encryptor.TransformFinalBlock(plaintext, 0, plaintext.Length); ICryptoTransform decryptor = cipher.CreateDecryptor(key, nonce, additional); byte[] dec = decryptor.TransformFinalBlock(enc, 0, enc.Length); byte[] result = new byte[ciphertext.Length + tag.Length]; Buffer.BlockCopy(ciphertext, 0, result, 0, ciphertext.Length); Buffer.BlockCopy(tag, 0, result, ciphertext.Length, tag.Length); Assert.AreEqual(result, enc); Assert.AreEqual(plaintext, dec); }
private void CheckVector(byte[] key, byte[] plaintext, byte[] additional, byte[] nonce, byte[] ciphertext, byte[] tag) { BulkCipherAlgorithmAesGcm cipher = new BulkCipherAlgorithmAesGcm(key.Length*8, tag.Length*8); ICryptoTransform encryptor = cipher.CreateEncryptor(key, nonce, additional); byte[] enc = encryptor.TransformFinalBlock(plaintext, 0, plaintext.Length); ICryptoTransform decryptor = cipher.CreateDecryptor(key, nonce, additional); byte[] dec = decryptor.TransformFinalBlock(enc, 0, enc.Length); byte[] result = new byte[ciphertext.Length + tag.Length]; Buffer.BlockCopy(ciphertext, 0, result, 0, ciphertext.Length); Buffer.BlockCopy(tag, 0, result, ciphertext.Length, tag.Length); Assert.AreEqual(result, enc); Assert.AreEqual(plaintext, dec); }