title: Using Sha256 or Rfc2898DeriveBytes to create IC
body: <p>Based on this: <a href="http://www.superstarcoders.com/blogs/posts/symmetric-encryption-in-c-sharp.aspx" rel="nofollow">http://www.superstarcoders.com/blogs/posts/symmetric-encryption-in-c-sharp.aspx</a></p>
  
  <p>I have written encryption/decryption of byte-arrays:</p>
  
  <pre><code>public static byte[] EncryptFile(string password, byte[] bytes, string salt)
      {
          using (RijndaelManaged aesEncryption = new RijndaelManaged())
          {
              DeriveBytes rgb = new Rfc2898DeriveBytes(password, Encoding.Unicode.GetBytes(salt));
              byte[] rgbKey = rgb.GetBytes(aesEncryption.KeySize &gt;&gt; 3);
              byte[] rgbIV = rgb.GetBytes(aesEncryption.BlockSize &gt;&gt; 3);
              aesEncryption.KeySize = 256;
              aesEncryption.Mode = CipherMode.CBC;
              aesEncryption.Padding = PaddingMode.PKCS7;
              aesEncryption.IV = rgbIV;
              aesEncryption.Key = rgbKey;
              using (ICryptoTransform crypto = aesEncryption.CreateEncryptor())
              {
                  return crypto.TransformFinalBlock(bytes, 0, bytes.Length);
              }
          }
      }
  
      public static byte[] DecryptFile(string password, byte[] bytes, string salt)
      {
          using (RijndaelManaged aesEncryption = new RijndaelManaged())
          {
              DeriveBytes rgb = new Rfc2898DeriveBytes(password, Encoding.Unicode.GetBytes(salt));
              byte[] rgbKey = rgb.GetBytes(aesEncryption.KeySize &gt;&gt; 3);
              byte[] rgbIV = rgb.GetBytes(aesEncryption.BlockSize &gt;&gt; 3);
              aesEncryption.KeySize = 256;
              aesEncryption.Mode = CipherMode.CBC;
              aesEncryption.Padding = PaddingMode.PKCS7;
              aesEncryption.IV = rgbIV;
              aesEncryption.Key = rgbKey;
              using (ICryptoTransform crypto = aesEncryption.CreateDecryptor())
              {
                  return crypto.TransformFinalBlock(bytes, 0, bytes.Length);
              }
          }
      }
  </code></pre>
  
  <p>But when calculating the IV and the key, should I instead use SHA256 instead of <code>Rfc2898DeriveBytes</code>? </p>