I want to generate an Initialization Vector (IV) for my AES encryption method. I have defined the key size as 256 (since I am using AES) so my IV needs to 32 bytes in length (256 / 8). I wish to store the IV as a string representation so using UTF-8, this would equate to a 16 character string.
Here is the code I am using to generate and return the IV ...
using (var aesProv = new AesCryptoServiceProvider())
{
aesProv.GenerateIV();
return System.Text.Encoding.Default.GetString(aesProv.IV);
}
How do I go about making sure that the IV is 16 characters in length? Can I count on a 16 character length being generated because I am using an AES library? AesCryptoServiceProvider