Пример #1
0
 /**
  * Crypts data using mcrypt or userland if not available.
  *
  * @param  string   data
  * @param  string   secret key
  * @param  bool     true if it should be crypted,
  *                  false if it should be decrypted
  * @return string   (de-)crypted data
  *
  * @access public
  */
 function cryptRC4($data, $secret, $crypt = true)
 {
     if (function_exists('mcrypt_module_open')) {
         $td = mcrypt_module_open('tripledes', '', 'ecb', '');
         $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
         mcrypt_generic_init($td, $secret, $iv);
         if ($crypt) {
             $data = mcrypt_generic($td, $data);
         } else {
             $data = mdecrypt_generic($td, $data);
         }
         mcrypt_generic_deinit($td);
         mcrypt_module_close($td);
     } else {
         $rc4 =& LiveUser::cryptRC4Factory($secret);
         if (!$rc4) {
             $this->stack->push(LIVEUSER_ERROR_CONFIG, 'exception', array(), 'RememberMe feature requires either the mcrypt extension or PEAR::Crypt_RC4');
             return false;
         }
         if ($crypt) {
             $rc4->crypt($data);
         } else {
             $rc4->decrypt($data);
         }
     }
     return $data;
 }