title: Generate key using Pass Phrase or AesCryptoServiceProvider?
body: <p>We using AES encryption to encrypt the data. Generating a key once in a year using some app(i.e console) so which way i have to choose to generate the key?</p>
  
  <p><strong>1. Do we need to generate the key using the Pass Phrase method?</strong></p>
  
  <p><strong>2. Or we have to choose the default generate key provided by AESCryptoServiceProvider?</strong></p>
  
  <p>The below method uses Pass Phrase for generating the encryption.</p>
  
  <p>Method 1:</p>
  
  <pre><code>private static readonly byte[] Salt = new byte[] { 10, 20, 30, 40, 50, 60, 70, 80 };
  
  private static byte[] CreateKey(string password, int keyBytes = 32)
  {
      const int Iterations = 300;
      var keyGenerator = new Rfc2898DeriveBytes(password, Salt, Iterations);
      return Convert.FromBase64String(keyGenerator.GetBytes(keyBytes));
  }
  </code></pre>
  
  <p>The below method uses <code>AesCryptoServiceProvider</code> for generating Key and we didn't use Pass Phrase</p>
  
  <p>Method 2:</p>
  
  <pre><code>var Key = default(string);
  
  using (var provider = new AesCryptoServiceProvider())
  {
      provider.GenerateKey();
      Key = System.Text.Encoding.ASCII.GetString(provider.Key);
  }
  </code></pre>
  
  <p>Edit:</p>
  
  <p>can we use this Random Number generation method?</p>
  
  <pre><code>public static byte[] RandomNumberGenerator()
  {
    var rngBytes = new byte[32];
    using (RandomNumberGenerator objNumberGenerator = new RNGCryptoServiceProvider())
    {
      objNumberGenerator.GetBytes(rngBytes);
      return rngBytes;
    }
  
  }
  </code></pre>