title: Rijndael initialization vector with 16 bytes
body: <p>I have to credit card number to be encrypted and stored in database as a string. I do the following</p>
  
  <pre><code>RijndaelManaged rijMan = new RijndaelManaged();
  byte[] encrypt = Encrypt(txtCredit.Text, rijMan.Key, rijMan.IV);
  string card = Convert.ToBase64String(encrypt);
  string key = Convert.ToBase64String(rijMan.Key);
  string iv = Convert.ToBase64String(rijMan.IV);
  </code></pre>
  
  <p>and this is encrypt function:</p>
  
  <pre><code>public static byte[] Encrypt(string message, byte[] key, byte[] iv)
  {
      byte[] encrypted;
      using (RijndaelManaged rijMan = new RijndaelManaged())
      {
          rijMan.Key = key;
          rijMan.IV = iv;
          ICryptoTransform encrypt = rijMan.CreateEncryptor(rijMan.Key, rijMan.IV);
          using (MemoryStream ms = new MemoryStream())
          {
              using (CryptoStream cs = new CryptoStream(ms, encrypt, CryptoStreamMode.Write))
              {
                  using (StreamWriter sw = new StreamWriter(cs))
                  {
                      sw.Write(message);
                  }
                  encrypted = ms.ToArray();
              }
          }
      }
      return encrypted;
  }
  </code></pre>
  
  <p>And i store them all in database. This seems to be fine. But when i retrieve back the string from database and use <code>System.Text.Encoding.UTF8.GetBytes(string)</code> to convert to <code>byte</code>, it throws an exception</p>
  
  <blockquote>
    <p>Specified initialization vector (IV) does not match the block size for this algorithm.</p>
  </blockquote>
  
  <p>Is it possible to generate the IV such that it is 16 bytes ? Thanks in advance for the reply</p>