/**
* A mcrypt-based encryption stream
*
- * @author Roland Haeder <webmaster@ship-simu.org>
+ * @author Roland Haeder <webmaster@shipsimu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Core Developer Team
* @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.org
+ * @link http://www.shipsimu.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*/
class McryptStream extends BaseStream implements EncryptableStream {
/**
- * Seperator on many places
+ * Separator on many places
*/
- const DATA_PAYLOAD_SEPERATOR = '|';
+ const DATA_PAYLOAD_SEPARATOR = '|';
/**
* Protected constructor
* @return $encrypted Encrypted string
*/
public function encryptStream ($str, $key = NULL) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: key[' . gettype($key) . ']=' . $key);
+
// Init crypto module
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
// Add some "payload" to the string
switch ($this->getRngInstance()->randomNumber(0, 8)) {
case 0:
- $payloadString = crc32($this->getRngInstance()->randomString(10)) . self::DATA_PAYLOAD_SEPERATOR . base64_encode($str) . self::DATA_PAYLOAD_SEPERATOR . crc32($this->getRngInstance()->randomString(20));
+ $payloadString = crc32($this->getRngInstance()->randomString(10)) . self::DATA_PAYLOAD_SEPARATOR . base64_encode($str) . self::DATA_PAYLOAD_SEPARATOR . crc32($this->getRngInstance()->randomString(20));
break;
case 1:
- $payloadString = crc32($this->getRngInstance()->randomString(10)) . self::DATA_PAYLOAD_SEPERATOR . base64_encode($str) . self::DATA_PAYLOAD_SEPERATOR . md5($this->getRngInstance()->randomString(20));
+ $payloadString = crc32($this->getRngInstance()->randomString(10)) . self::DATA_PAYLOAD_SEPARATOR . base64_encode($str) . self::DATA_PAYLOAD_SEPARATOR . md5($this->getRngInstance()->randomString(20));
break;
case 2:
- $payloadString = crc32($this->getRngInstance()->randomString(10)) . self::DATA_PAYLOAD_SEPERATOR . base64_encode($str) . self::DATA_PAYLOAD_SEPERATOR . sha1($this->getRngInstance()->randomString(20));
+ $payloadString = crc32($this->getRngInstance()->randomString(10)) . self::DATA_PAYLOAD_SEPARATOR . base64_encode($str) . self::DATA_PAYLOAD_SEPARATOR . sha1($this->getRngInstance()->randomString(20));
break;
case 3:
- $payloadString = md5($this->getRngInstance()->randomString(10)) . self::DATA_PAYLOAD_SEPERATOR . base64_encode($str) . self::DATA_PAYLOAD_SEPERATOR . crc32($this->getRngInstance()->randomString(20));
+ $payloadString = md5($this->getRngInstance()->randomString(10)) . self::DATA_PAYLOAD_SEPARATOR . base64_encode($str) . self::DATA_PAYLOAD_SEPARATOR . crc32($this->getRngInstance()->randomString(20));
break;
case 4:
- $payloadString = md5($this->getRngInstance()->randomString(10)) . self::DATA_PAYLOAD_SEPERATOR . base64_encode($str) . self::DATA_PAYLOAD_SEPERATOR . md5($this->getRngInstance()->randomString(20));
+ $payloadString = md5($this->getRngInstance()->randomString(10)) . self::DATA_PAYLOAD_SEPARATOR . base64_encode($str) . self::DATA_PAYLOAD_SEPARATOR . md5($this->getRngInstance()->randomString(20));
break;
case 5:
- $payloadString = md5($this->getRngInstance()->randomString(10)) . self::DATA_PAYLOAD_SEPERATOR . base64_encode($str) . self::DATA_PAYLOAD_SEPERATOR . sha1($this->getRngInstance()->randomString(20));
+ $payloadString = md5($this->getRngInstance()->randomString(10)) . self::DATA_PAYLOAD_SEPARATOR . base64_encode($str) . self::DATA_PAYLOAD_SEPARATOR . sha1($this->getRngInstance()->randomString(20));
break;
case 6:
- $payloadString = sha1($this->getRngInstance()->randomString(10)) . self::DATA_PAYLOAD_SEPERATOR . base64_encode($str) . self::DATA_PAYLOAD_SEPERATOR . crc32($this->getRngInstance()->randomString(20));
+ $payloadString = sha1($this->getRngInstance()->randomString(10)) . self::DATA_PAYLOAD_SEPARATOR . base64_encode($str) . self::DATA_PAYLOAD_SEPARATOR . crc32($this->getRngInstance()->randomString(20));
break;
case 7:
- $payloadString = sha1($this->getRngInstance()->randomString(10)) . self::DATA_PAYLOAD_SEPERATOR . base64_encode($str) . self::DATA_PAYLOAD_SEPERATOR . md5($this->getRngInstance()->randomString(20));
+ $payloadString = sha1($this->getRngInstance()->randomString(10)) . self::DATA_PAYLOAD_SEPARATOR . base64_encode($str) . self::DATA_PAYLOAD_SEPARATOR . md5($this->getRngInstance()->randomString(20));
break;
case 8:
- $payloadString = sha1($this->getRngInstance()->randomString(10)) . self::DATA_PAYLOAD_SEPERATOR . base64_encode($str) . self::DATA_PAYLOAD_SEPERATOR . sha1($this->getRngInstance()->randomString(20));
+ $payloadString = sha1($this->getRngInstance()->randomString(10)) . self::DATA_PAYLOAD_SEPARATOR . base64_encode($str) . self::DATA_PAYLOAD_SEPARATOR . sha1($this->getRngInstance()->randomString(20));
break;
}
$payloadString = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $encrypted, MCRYPT_MODE_ECB, $iv);
// Get the real string out
- $strArray = explode(self::DATA_PAYLOAD_SEPERATOR, $payloadString);
+ $strArray = explode(self::DATA_PAYLOAD_SEPARATOR, $payloadString);
// Does the element count match?
assert(count($strArray) == 3);
* @throws UnsupportedOperationException If this method is called (which is a mistake)
*/
public function streamData ($data) {
- $this->debugOutput('Unhandled ' . strlen($data) . ' bytes in this stream.');
+ self::createDebugInstance(__CLASS__)->debugOutput('Unhandled ' . strlen($data) . ' bytes in this stream.');
throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
}
}