var aes = new AesCryptoServiceProvider {Mode = CipherMode.CBC};
var encryptor = aes.CreateEncryptor();
var decryptor = aes.CreateDecryptor();
var image = File.ReadAllBytes("image.png");
var encryptedImagePart = encryptor.TransformFinalBlock(image, 0, 1024);
using (var fs = File.Create("encrypted"))
{
fs.Write(encryptedImagePart, 0 , encryptedImagePart.Length);
fs.Write(image, 1024, image.Length - 1024);
fs.Flush(true);
}
var encryptedImage = File.ReadAllBytes("encrypted");
var decryptedImagePart = decryptor.TransformFinalBlock(encryptedImage, 0, encryptedImagePart.Length);
using (var fs = File.Create("decrypted"))
{
fs.Write(decryptedImagePart, 0, decryptedImagePart.Length);
fs.Write(encryptedImage, encryptedImagePart.Length, encryptedImage.Length - encryptedImagePart.Length);
fs.Flush(true);
}