title: How to do AES256 decryption in PHP?
body: <p>I have an encrypted bit of text that I need to decrypt. It's encrypted with AES-256-CBC. I have the encrypted text, key, and iv. However, no matter what I try I just can't seem to get it to work.</p>
  
  <p>The internet has suggested that mcrypt's Rijndael cypher should be able to do this, so here's what I have now:</p>
  
  <pre><code>function decrypt_data($data, $iv, $key) {
      $cypher = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
  
      // initialize encryption handle
      if (mcrypt_generic_init($cypher, $key, $iv) != -1) {
          // decrypt
          $decrypted = mdecrypt_generic($cypher, $data);
  
          // clean up
          mcrypt_generic_deinit($cypher);
          mcrypt_module_close($cypher);
  
          return $decrypted;
      }
  
      return false;
  }
  </code></pre>
  
  <p>As it stands now I get 2 warnings and the output is gibberish:</p>
  
  <pre><code>Warning: mcrypt_generic_init() [function.mcrypt-generic-init]: Key size too large; supplied length: 64, max: 32 in /var/www/includes/function.decrypt_data.php on line 8
  Warning: mcrypt_generic_init() [function.mcrypt-generic-init]: Iv size incorrect; supplied length: 32, needed: 16 in /var/www/includes/function.decrypt_data.php on line 8
  </code></pre>
  
  <p>Any help would be appreciated.</p>