title: Appending IV to an
body: <p>I am in the process of writing a small encoding class which takes a <code>byte[]</code> array, and cyphers it. As the IV can be made public, I wish to prepend it to the ciphertext to use for decryption.</p>
  
  <p>Following the MSDN Documentation and some SO Post source (Cant find link), I started the stream with the raw IV;</p>
  
  <pre><code>//Start encryption process
          using (var msEncrypt = new MemoryStream())
          {
              using (var csEncrypt = new CryptoStream(msEncrypt, encryptor.CreateEncryptor(), CryptoStreamMode.Write))
              {
                  using (var swWriter = new StreamWriter(csEncrypt))
                  {
  
                      //Write all data to the stream.
                      swWriter.Write(encryptor.IV);
                      swWriter.Write(plainTextRaw);
  
  
  
                  }
  
              }
  
              Console.WriteLine("Encrypted Value: {0}", BitConverter.ToString(msEncrypt.ToArray()).Replace("-", String.Empty));
              return msEncrypt.ToArray();
  
          }
  </code></pre>
  
  <p>However, upon writing a simple unit test extracting the first 16 bytes, they do not seem to match.</p>
  
  <p>I am certain the IV is being encrypted within the stream, so where is the best place to inject it?</p>