Subversion-Projekte lars-tiefland.ci

Revision

Revision 2049 | Revision 2242 | Zur aktuellen Revision | Ganze Datei anzeigen | Leerzeichen ignorieren | Details | Blame | Letzte Änderung | Log anzeigen | RSS feed

Revision 2049 Revision 2107
Zeile 120... Zeile 120...
120
				return $this->encryption_key;
120
				return $this->encryption_key;
121
			}
121
			}
Zeile 122... Zeile 122...
122
 
122
 
Zeile 123... Zeile 123...
123
			$key = config_item('encryption_key');
123
			$key = config_item('encryption_key');
124
 
124
 
125
			if ( ! strlen($key))
125
			if ( ! self::strlen($key))
126
			{
126
			{
127
				show_error('In order to use the encryption class requires that you set an encryption key in your config file.');
127
				show_error('In order to use the encryption class requires that you set an encryption key in your config file.');
Zeile 250... Zeile 250...
250
	protected function _xor_decode($string, $key)
250
	protected function _xor_decode($string, $key)
251
	{
251
	{
252
		$string = $this->_xor_merge($string, $key);
252
		$string = $this->_xor_merge($string, $key);
Zeile 253... Zeile 253...
253
 
253
 
254
		$dec = '';
254
		$dec = '';
255
		for ($i = 0, $l = strlen($string); $i < $l; $i++)
255
		for ($i = 0, $l = self::strlen($string); $i < $l; $i++)
256
		{
256
		{
257
			$dec .= ($string[$i++] ^ $string[$i]);
257
			$dec .= ($string[$i++] ^ $string[$i]);
Zeile 258... Zeile 258...
258
		}
258
		}
Zeile 273... Zeile 273...
273
	 */
273
	 */
274
	protected function _xor_merge($string, $key)
274
	protected function _xor_merge($string, $key)
275
	{
275
	{
276
		$hash = $this->hash($key);
276
		$hash = $this->hash($key);
277
		$str = '';
277
		$str = '';
-
 
278
 
278
		for ($i = 0, $ls = strlen($string), $lh = strlen($hash); $i < $ls; $i++)
279
		for ($i = 0, $ls = self::strlen($string), $lh = self::strlen($hash); $i < $ls; $i++)
279
		{
280
		{
280
			$str .= $string[$i] ^ $hash[($i % $lh)];
281
			$str .= $string[$i] ^ $hash[($i % $lh)];
281
		}
282
		}
Zeile 282... Zeile 283...
282
 
283
 
Zeile 293... Zeile 294...
293
	 * @return	string
294
	 * @return	string
294
	 */
295
	 */
295
	public function mcrypt_encode($data, $key)
296
	public function mcrypt_encode($data, $key)
296
	{
297
	{
297
		$init_size = mcrypt_get_iv_size($this->_get_cipher(), $this->_get_mode());
298
		$init_size = mcrypt_get_iv_size($this->_get_cipher(), $this->_get_mode());
298
		$init_vect = mcrypt_create_iv($init_size, MCRYPT_RAND);
299
		$init_vect = mcrypt_create_iv($init_size, MCRYPT_DEV_URANDOM);
299
		return $this->_add_cipher_noise($init_vect.mcrypt_encrypt($this->_get_cipher(), $key, $data, $this->_get_mode(), $init_vect), $key);
300
		return $this->_add_cipher_noise($init_vect.mcrypt_encrypt($this->_get_cipher(), $key, $data, $this->_get_mode(), $init_vect), $key);
300
	}
301
	}
Zeile 301... Zeile 302...
301
 
302
 
Zeile 311... Zeile 312...
311
	public function mcrypt_decode($data, $key)
312
	public function mcrypt_decode($data, $key)
312
	{
313
	{
313
		$data = $this->_remove_cipher_noise($data, $key);
314
		$data = $this->_remove_cipher_noise($data, $key);
314
		$init_size = mcrypt_get_iv_size($this->_get_cipher(), $this->_get_mode());
315
		$init_size = mcrypt_get_iv_size($this->_get_cipher(), $this->_get_mode());
Zeile 315... Zeile 316...
315
 
316
 
316
		if ($init_size > strlen($data))
317
		if ($init_size > self::strlen($data))
317
		{
318
		{
318
			return FALSE;
319
			return FALSE;
Zeile 319... Zeile 320...
319
		}
320
		}
320
 
321
 
-
 
322
		$init_vect = self::substr($data, 0, $init_size);
321
		$init_vect = substr($data, 0, $init_size);
323
		$data      = self::substr($data, $init_size);
322
		$data = substr($data, $init_size);
324
 
Zeile 323... Zeile 325...
323
		return rtrim(mcrypt_decrypt($this->_get_cipher(), $key, $data, $this->_get_mode(), $init_vect), "\0");
325
		return rtrim(mcrypt_decrypt($this->_get_cipher(), $key, $data, $this->_get_mode(), $init_vect), "\0");
Zeile 337... Zeile 339...
337
	protected function _add_cipher_noise($data, $key)
339
	protected function _add_cipher_noise($data, $key)
338
	{
340
	{
339
		$key = $this->hash($key);
341
		$key = $this->hash($key);
340
		$str = '';
342
		$str = '';
Zeile 341... Zeile 343...
341
 
343
 
342
		for ($i = 0, $j = 0, $ld = strlen($data), $lk = strlen($key); $i < $ld; ++$i, ++$j)
344
		for ($i = 0, $j = 0, $ld = self::strlen($data), $lk = self::strlen($key); $i < $ld; ++$i, ++$j)
343
		{
345
		{
344
			if ($j >= $lk)
346
			if ($j >= $lk)
345
			{
347
			{
346
				$j = 0;
348
				$j = 0;
Zeile 367... Zeile 369...
367
	protected function _remove_cipher_noise($data, $key)
369
	protected function _remove_cipher_noise($data, $key)
368
	{
370
	{
369
		$key = $this->hash($key);
371
		$key = $this->hash($key);
370
		$str = '';
372
		$str = '';
Zeile 371... Zeile 373...
371
 
373
 
372
		for ($i = 0, $j = 0, $ld = strlen($data), $lk = strlen($key); $i < $ld; ++$i, ++$j)
374
		for ($i = 0, $j = 0, $ld = self::strlen($data), $lk = self::strlen($key); $i < $ld; ++$i, ++$j)
373
		{
375
		{
374
			if ($j >= $lk)
376
			if ($j >= $lk)
375
			{
377
			{
376
				$j = 0;
378
				$j = 0;
Zeile 475... Zeile 477...
475
	public function hash($str)
477
	public function hash($str)
476
	{
478
	{
477
		return hash($this->_hash_type, $str);
479
		return hash($this->_hash_type, $str);
478
	}
480
	}
Zeile -... Zeile 481...
-
 
481
 
-
 
482
	// --------------------------------------------------------------------
-
 
483
 
-
 
484
	/**
-
 
485
	 * Byte-safe strlen()
-
 
486
	 *
-
 
487
	 * @param	string	$str
-
 
488
	 * @return	int
-
 
489
	 */
-
 
490
	protected static function strlen($str)
-
 
491
	{
-
 
492
		return defined('MB_OVERLOAD_STRING')
-
 
493
			? mb_strlen($str, '8bit')
-
 
494
			: strlen($str);
-
 
495
	}
-
 
496
 
-
 
497
	// --------------------------------------------------------------------
-
 
498
 
-
 
499
	/**
-
 
500
	 * Byte-safe substr()
-
 
501
	 *
-
 
502
	 * @param	string	$str
-
 
503
	 * @param	int	$start
-
 
504
	 * @param	int	$length
-
 
505
	 * @return	string
-
 
506
	 */
-
 
507
	protected static function substr($str, $start, $length = NULL)
-
 
508
	{
-
 
509
		if (defined('MB_OVERLOAD_STRING'))
-
 
510
		{
-
 
511
			// mb_substr($str, $start, null, '8bit') returns an empty
-
 
512
			// string on PHP 5.3
-
 
513
			isset($length) OR $length = ($start >= 0 ? self::strlen($str) - $start : -$start);
-
 
514
			return mb_substr($str, $start, $length, '8bit');
-
 
515
		}
-
 
516
 
-
 
517
		return isset($length)
-
 
518
			? substr($str, $start, $length)
-
 
519
			: substr($str, $start);
479
 
520
	}