title: AES Encrypt and Decrypt
body: <p>I write an application by swift, i need AES Encrypt and Decrypt functionality, i received encrypted data from another .Net solution, but i can't find something to do it.</p>
  
  <p>This is my .net Encryption:</p>
  
  <pre><code> public static byte[] AES_Encrypt(byte[] bytesToBeEncrypted, byte[] passwordBytes)
      {
          byte[] encryptedBytes = null;
  
          byte[] saltBytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
  
          using (MemoryStream ms = new MemoryStream())
          {
              using (RijndaelManaged AES = new RijndaelManaged())
              {
                  AES.KeySize = 256;
                  AES.BlockSize = 128;
  
                  var key = new Rfc2898DeriveBytes(passwordBytes, saltBytes, 1000);
                  AES.Key = key.GetBytes(AES.KeySize / 8);
                  AES.IV = key.GetBytes(AES.BlockSize / 8);
  
                  AES.Mode = CipherMode.CBC;
  
                  using (var cs = new CryptoStream(ms, AES.CreateEncryptor(), CryptoStreamMode.Write))
                  {
                      cs.Write(bytesToBeEncrypted, 0, bytesToBeEncrypted.Length);
                      cs.Close();
                  }
                  encryptedBytes = ms.ToArray();
              }
          }
  
          return encryptedBytes;
      }
  </code></pre>
  
  <p>I need to decrypt function in swift.</p>