using System.Security.Cryptography;
public static void Main()
byte[] input = Encoding.UTF8.GetBytes("The quick brown fox jumps over the lazy dog");
var encr0 = encrypt(subArray(input, 0, blockSize * 2));
var encr1 = encrypt(subArray(input, 0, blockSize));
var encr2 = encrypt(subArray(input, blockSize, blockSize), subArray(encr1, 0, blockSize));
Assert.IsTrue(encr2.SequenceEqual(subArray(encr0, blockSize)));
var encrAll = encrypt(input);
static byte[] encrypt(byte[] input, byte[] iv = null)
var aes = new AesManaged();
aes.Key = new byte[16] { 0x0F, 0xD4, 0x33, 0x82, 0xF4, 0xDF, 0x62, 0xA5, 0x55, 0x7C, 0x6E, 0x92, 0xC5, 0x64, 0x67, 0xA9 };
aes.IV = (iv != null) ? iv : new byte[16] { 0xB3, 0x87, 0xDA, 0xA0, 0x47, 0x7C, 0x52, 0x76, 0xCB, 0x3A, 0x69, 0x9B, 0x0F, 0x82, 0xAF, 0xA7 };
using (var stream = new MemoryStream())
using (var cryptoStream = new CryptoStream(stream,
aes.CreateEncryptor(), CryptoStreamMode.Write))
cryptoStream.Write(input, 0, input.Length);
cryptoStream.FlushFinalBlock();
static byte[] subArray(byte[] source, int start, int length = -1)
if (length == -1) length = source.Length - start;
var target = new byte[length];
Buffer.BlockCopy(source, start, target, 0, length);
static void Write(byte[] data)
string hex = Convert.ToHexString(data);
Console.WriteLine(System.Text.RegularExpressions.Regex.Replace(hex, ".{32}", "$0 "));