title: Empty or null array using System.Security.Cryptography
body: <p>I'm trying to use the AES encryption method in C# using this code:</p>
  
  <pre><code>public static byte[] encryptData(string plaintext)
      {
          Aes myAes = Aes.Create();
          byte[] encrypted = EncryptStringToBytes_Aes(plaintext,myAes.Key, myAes.IV);
          return encrypted;
      }
  
  static byte[] EncryptStringToBytes_Aes(string plainText, byte[] Key, byte[] IV)
      {
          if (plainText == null || plainText.Length &lt;= 0)
              throw new ArgumentNullException("plainText");
          if (Key == null || Key.Length &lt;= 0)
              throw new ArgumentNullException("Key");
          if (IV == null || IV.Length &lt;= 0)
              throw new ArgumentNullException("IV");
          byte[] encrypted;
          Aes aesAlg = Aes.Create();
          aesAlg.Key = Key;
          aesAlg.Key = IV;
          ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);
          MemoryStream msEncrypt = new MemoryStream();
          CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write);
          StreamWriter swEncrypt = new StreamWriter(csEncrypt);
          swEncrypt.Write(plainText);
          encrypted = msEncrypt.ToArray();
          return encrypted;
      }
  </code></pre>
  
  <p>And calling the functions like this:</p>
  
  <pre><code>byte[] encrypt = Security.encryptData("Hi, how are you?");
  </code></pre>
  
  <p>But the returned byte array is always empty.</p>
  
  <p>I'm trying to use this to encrypt values like passwords on my app.config file.</p>