title: Program crashes when setting values in Rijndael class
body: <p>I currently have the following code.</p>
  
  <p>I am generating a <code>byte array</code> from a hard coded random <code>string</code>.</p>
  
  <p>Now I noticed that when setting up a <code>Rijndael</code> class the application crashes when setting the key value. Any suggestions on why it crashes when the key value is set.</p>
  
  <pre><code>int olength = 18; 
  string HKey = "ABCDEFGHIJKL111100002222"; //Some random string 
  byte[] key = Convert.FromBase64String(HardcodedKey); //key.length = 18
  byte[] iv = Encryption.GenerateRandomBytes(olength);
  CryptoStream cs = Encryption.AES128Stream(key, iv, Context.Response.Body);
  </code></pre>
  
  <p>Now the above method being called is give below</p>
  
  <pre><code>public static CryptoStream AES128Stream(byte[] key, byte[] iv, Stream stream)
  {
      try
      {
          Rijndael rijndael = Rijndael.Create();
          rijndael.Mode = CipherMode.CBC;
          rijndael.Padding = PaddingMode.PKCS7;
          rijndael.KeySize = 128;
          rijndael.BlockSize = 128;
          rijndael.Key = key;  ///----&gt;CRASHES HERE
          rijndael.IV = iv;
  
          ICryptoTransform rijndaelEncryptor = rijndael.CreateEncryptor();
          return new CryptoStream(stream, rijndaelEncryptor, CryptoStreamMode.Write);
      }
      catch (Exception e)
      {
          throw e;
      }
  }
  </code></pre>
  
  <p>In additional information it states</p>
  
  <blockquote>
    <p>Additional information: Specified key is not a valid size for this
    algorithm.</p>
  </blockquote>
  
  <p>In that case what string can I use that will work ? Why is this string not working ?</p>