Guest User

Untitled

a guest
Feb 1st, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.52 KB | None | 0 0
  1. <?php
  2. class AES {
  3.     function __construct($options) {
  4.         if (isset($options)) {
  5.             $this->options = $options;
  6.         } else {
  7.             throw new Exception('Unable to set AES Options');
  8.         }
  9.     }
  10.     public function encrypt() {
  11.         if (isset($this->options['encryption_key'])) {
  12.             if (isset($this->options['data_to_encrypt']) && !empty($this->options['data_to_encrypt'])) {
  13.                 return trim(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->options['encryption_key'], $this->options['data_to_encrypt'], MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND)));
  14.             } else {
  15.                 throw new Exception('No data to be encrypted specified.');
  16.             }
  17.         } else {
  18.             throw new Exception('No encryption key specified.');
  19.         }
  20.     }
  21.  
  22.     public function decrypt() {
  23.         if (isset($this->options['encryption_key'])) {
  24.             if (isset($this->options['data_to_decrypt']) && !empty($this->options['data_to_decrypt'])) {
  25.                 return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $this->options['encryption_key'], base64_decode($this->options['data_to_decrypt']), MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND)));
  26.             } else {
  27.                 throw new Exception('No data to be decrypted specified.');
  28.             }
  29.         } else {
  30.             throw new Exception('No encryption key specified.');
  31.         }
  32.     }
  33. }
  34. ?>
Advertisement
Add Comment
Please, Sign In to add comment