Hi, everybody
I am working on AES encryption app. I need to split the file into blocks, then encrypt each block individually. What I had so far is below:

    byte[] sourceBuffer = File.ReadAllBytes(inputFile);
    byte[] destBuffer = new byte[sourceBuffer.Length];
    byte[] toEncrypt = new byte[16];

            // Encrypt each block.
            for (int offset = 0; offset < sourceBuffer.Length; offset += 16)
            {

                Array.Copy(sourceBuffer, offset, toEncrypt, 0, 16); // copying from the source into 16 byte array size

                Array.Copy(EncryptByte(toEncrypt), 0, destBuffer, offset, 16); 

            }
            System.IO.File.WriteAllBytes(outputFile, destBuffer);

            /********************************************************************************************************/

                   public static byte[] EncryptByte(byte[] input)
        {
            RijndaelManaged aes = new RijndaelManaged();
            MemoryStream ms = new MemoryStream();
            aes.IV = Iv;
            aes.Key = Key;
            aes.Padding = PaddingMode.Zeros;

            CryptoStream cs = new CryptoStream(ms,aes.CreateEncryptor(), CryptoStreamMode.Write);
            cs.Write(input, 0, input.Length);
            cs.Close();
            return ms.ToArray();
        }
This article has been dead for over six months. Start a new discussion instead.