Advertisement
DisasterMan

AES-256 Decryption with PHP Mcrypt (CodeIgniter)

Oct 4th, 2012
1,195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.06 KB | None | 0 0
  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*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement