[ Index ]

PHP Cross Reference of Mambo 4.6.5

[ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/includes/ -> cypher.class.php (source)

   1  <?php
   2  /**
   3  * @package Mambo
   4  * @author Mambo Foundation Inc see README.php
   5  * @copyright (C) 2000 - 2009 Mambo Foundation Inc.
   6  * See COPYRIGHT.php for copyright notices and details.
   7  * @license GNU/GPL Version 2, see LICENSE.php
   8  *
   9  * Redistributions of files must retain the above copyright notice.
  10  *
  11  * Mambo is free software; you can redistribute it and/or
  12  * modify it under the terms of the GNU General Public License
  13  * as published by the Free Software Foundation; version 2 of the License.
  14  */
  15  
  16  class mosCypher {
  17      var $_key = '';
  18      var $plain_text;
  19      var $enc_text;
  20      function &getInstance() {
  21          static $instance;
  22          if (!is_object($instance)) {
  23              $instance = new mosCypher;
  24              $instance->_key = mamboCore::get('mosConfig_secret');
  25          }
  26          return $instance;
  27      }
  28  	function encrypt($plain_text) {
  29          static $instance;
  30          if (!is_object($instance)) $instance =& mosCypher::getInstance();
  31          static $handler;
  32          if (!is_object($handler)) $handler =& mosCypherHandler::getInstance();
  33          $instance->enc_text = $handler->encrypt($instance->_key, $plain_text, strlen($plain_text));
  34          return $instance->enc_text;
  35      }
  36  	function decrypt($enc_text) {
  37          static $instance;
  38          if (!is_object($instance)) $instance =& mosCypher::getInstance();
  39          static $handler;
  40          if (!is_object($handler)) $handler =& mosCypherHandler::getInstance();
  41          $instance->plain_text = $handler->decrypt($instance->_key, $enc_text);
  42          return $instance->plain_text;
  43      }
  44  	function encryptQuery($query) {
  45          static $handler;
  46          if (!is_object($handler)) $handler =& mosCypherHandler::getInstance();
  47          return base64_encode(urlencode($handler->encrypt($query)));
  48      }
  49  	function decryptQuery($query) {
  50          static $handler;
  51          if (!is_object($handler)) $handler =& mosCypherHandler::getInstance();
  52          return $handler->decrypt(urldecode(base64_decode($query)));
  53      }
  54  	function get($key='') {
  55          $key = trim($key);
  56          if ( strlen($key) == 0 ) return null;
  57          if ( $key{0} == '_' ) return null;
  58          static $instance;
  59          if (!is_object($instance)) $instance =& mosCypher::getInstance();
  60          if ( !isset($instance->$key) ) return null;
  61          return $instance->$key;
  62      }
  63  	function set($key='', $value='') {
  64          $key = trim($key);
  65          if ( strlen($key) == 0 ) return;
  66          if ( $key{0} == '_' ) return;
  67          static $instance;
  68          if (!is_object($instance)) $instance =& mosCypher::getInstance();
  69          if ( !isset($instance->$key) ) return;
  70          $instance->$key = $value;
  71      }
  72  	function setKey($value='') {
  73          static $instance;
  74          if (!is_object($instance)) $instance =& mosCypher::getInstance();
  75          if ( strlen($value) !== 0 ) $instance->_key = $value;
  76      }
  77  } // end class mosCypher
  78  
  79  class mosCypherHandler {
  80      function &getInstance() {
  81          static $instance;
  82          if (!is_object($instance)) {
  83              require_once(mamboCore::get('mosConfig_absolute_path').'/includes/tm_encrypt/std.encryption.class.inc');
  84              $instance = new encryption_class();
  85          }
  86          return $instance;
  87      }
  88  	function encrypt($plain_text, $key) {
  89          static $instance;
  90          if (!is_object($instance)) $instance =& mosCypherHandler::getInstance();
  91          return $instance->encrypt($plain_text, $key);
  92      }
  93  	function decrypt($enc_text, $key) {
  94          static $instance;
  95          if (!is_object($instance)) $instance =& mosCypherHandler::getInstance();
  96          return $instance->decrypt($enc_text, $key);
  97      }
  98  } // end class mosCypherHandler
  99  ?>