title: How to use AES with 256 bit or higher in .NET Core
body: <p>I have the code below that works with 128 bit Hex Key. However, when i supply 256 bit Hex key (or higher) it throws error </p>
  
  <blockquote>
    <p>Message: System.ArgumentException : Specified key is not a valid size
    for this algorithm. Parameter name: rgbKey</p>
  </blockquote>
  
  <pre><code>        public static string Encrypt(string text, string keyString)
          {
              var key = Encoding.UTF8.GetBytes(keyString);
  
              using (var aesAlg = Aes.Create())
              {
                  using (var encryptor = aesAlg.CreateEncryptor(key, aesAlg.IV))
                  {
                      using (var msEncrypt = new MemoryStream())
                      {
                          using (var csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
                          using (var swEncrypt = new StreamWriter(csEncrypt))
                          {
                              swEncrypt.Write(text);
                          }
  
                          var iv = aesAlg.IV;
  
                          var decryptedContent = msEncrypt.ToArray();
  
                          var result = new byte[iv.Length + decryptedContent.Length];
  
                          Buffer.BlockCopy(iv, 0, result, 0, iv.Length);
                          Buffer.BlockCopy(decryptedContent, 0, result, iv.Length, decryptedContent.Length);
  
                          return Convert.ToBase64String(result);
                      }
                  }
              }
          }
  </code></pre>
  
  <p>How do i use AES with 256 bit or higher Key?</p>