title: AES one-shot API decryption throwing if it has not encrypted before
body: <p>I'm attempting to roundtrip crypting some data with the <a href="https://github.com/dotnet/runtime/issues/2406" rel="nofollow noreferrer">new .NET 6 AES one-shot APIs</a>.</p>
  <p>The following example works as expected:</p>
  <pre class="lang-cs prettyprint-override"><code>using System.Security.Cryptography;
  
  string key = &quot;1234567890123456&quot;;
  byte[] keyBytes = Encoding.ASCII.GetBytes(key);
  
  string dec = &quot;Hello One-Shot API!&quot;;
  byte[] decBytes = Encoding.ASCII.GetBytes(dec);
  
  // Encrypt
  using Aes aes = Aes.Create();
  byte[] encBytes = aes.EncryptCbc(decBytes, keyBytes);
  
  // Decrypt again
  byte[] recBytes = aes.DecryptCbc(encBytes, keyBytes);
  string rec = Encoding.ASCII.GetString(recBytes);
  
  Debug.Assert(rec == dec);
  </code></pre>
  <p>But if I create a <em>new</em> <code>Aes</code> instance to call <code>DecryptCbc</code> on, it throws a <code>System.Security.Cryptography.CryptographicException: Padding is invalid and cannot be removed.</code> exception:</p>
  <pre class="lang-cs prettyprint-override"><code>...
  // Encrypt
  using Aes aes = Aes.Create();
  byte[] encBytes = aes.EncryptCbc(decBytes, keyBytes);
  
  // Decrypt again - this time with new instance
  using Aes aes2 = Aes.Create();
  byte[] recBytes = aes2.DecryptCbc(encBytes, keyBytes); // &lt;- throws
  ...
  </code></pre>
  <p>Am I missing something here? Is there state set up in an <code>Aes</code> instance when calling <code>EncryptCbc</code> that doesn't exist when only using it for decryption? Do I have to keep the <code>Aes</code> instance around, and then how would I use it for decryption initially if I haven't encrypted with it before?</p>