SHARE
TWEET

AES-256 Decryption with PHP Mcrypt (CodeIgniter)

DisasterMan Oct 4th, 2012 1,096 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. //http://blog.absolutedisaster.co.uk/aes-256-decryption-with-php-mcrypt
  3.  
  4. class Aes extends CI_Controller {
  5.  
  6.     private $encrypted,
  7.             $key,
  8.             $iv;
  9.  
  10.     public function index()
  11.     {
  12.  
  13.         $this->config->load('aes');
  14.  
  15.         $this->key = $this->config->item('aes_secret');
  16.  
  17.         $this->iv = $this->config->item('aes_iv');
  18.  
  19.         $this->encrypted = $this->input->post('accesstoken');
  20.  
  21.         echo $this->aes256_decrypt();
  22.  
  23.     }
  24.  
  25.     private function aes256_decrypt()
  26.     {
  27.  
  28.         return trim(
  29.             mcrypt_decrypt(
  30.                 MCRYPT_RIJNDAEL_128,// AES 256 decryption is acheived with Rijndael 128
  31.                                     // http://kix.in/2008/07/22/aes-256-using-php-mcrypt/
  32.                 $this->key,
  33.                 base64_decode($this->encrypted),
  34.                 MCRYPT_MODE_CBC,
  35.                 $this->iv
  36.             )
  37.         );
  38.  
  39.     }
  40. }
  41. /*End of file aes.php*/
  42. /*Location .application/controllers/aes.php*/
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top