title: Using the AesGcm class
body: <p>I just noticed that .NET Standard 2.1/.NET Core 3.0 finally added a <a href="https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.aesgcm?view=netstandard-2.1" rel="noreferrer">class for AES-GCM encryption</a>.</p>
  
  <p>However, its API seems to be slightly different from the usual .NET crypto classes: Its <a href="https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.aesgcm.encrypt?view=netstandard-2.1" rel="noreferrer"><code>Encrypt</code></a> function asks for pre-allocated byte arrays for the cipher text and the tag, instead of providing them itself. Unfortunately there is no example in the docs showing proper usage of that class.</p>
  
  <p>I know how to calculate the expected cipher text size for an AES encryption in theory, but I wonder whether it is really the intended approach to kind of "guess" a buffer size for the cipher text there. Usually crypto libraries provide functions that take care of those calculations.</p>
  
  <p>Does someone have an example on how to <em>properly</em> encrypt a byte array using <code>AesGcm</code>?</p>