title: AES key converting to string and byte[] C#
body: <p>I have an application that generates a AES Key (using Security.Cryptography). I take that AES Key, convert it to string and put it in a cookie like this:</p>
  
  <pre><code>string keyToSend = Encoding.UTF8.GetString(CurrentKey);
  HttpCookie sessionKeyCookie = new HttpCookie("SessionKey", JsonConvert.SerializeObject(keyToSend));
  </code></pre>
  
  <p>keyToSend looks like this: "���K��Ui ����&amp;��Ӂ*��()".</p>
  
  <p>Then, I want to take back that key and use it to decrypt something, and I do this:</p>
  
  <pre><code>string keyString = JsonConvert.DeserializeObject&lt;string&gt;(context.Cookies["SessionKey"].Value);
  byte[] ascii = Encoding.ASCII.GetBytes(cevaString);
  byte[] utf8 = Encoding.UTF8.GetBytes(cevaString);
  byte[] utf32 = Encoding.UTF32.GetBytes(cevaString);
  </code></pre>
  
  <p>Also, my keyToString looks like this: "���K��Ui ����&amp;��Ӂ*��()".</p>
  
  <p>And my browser cookie looks like this: "�\u0010��K��Ui �\u0010�\u000f�\u001f\u0005�\u0012\u0018&amp;��Ӂ*��()\u001e" </p>
  
  <p><strong>The initial key should have 256bits</strong>, so 32 entries in that array, but all my variables (ascii, utf8, utf32) have different lengths. <strong>Why is that, how can I retrieve the cookie and convert it to a byte[32] array?</strong></p>