]> git.mxchange.org Git - core.git/blobdiff - inc/classes/main/rng/class_RandomNumberGenerator.php
Added parameter 'key' to encryption methods to allow own keys
[core.git] / inc / classes / main / rng / class_RandomNumberGenerator.php
index fd416433a52d49f55495d12fc8456d27ca92306c..00eb513fe4f2e9158128fbcaddefc79fad9ba7ff 100644 (file)
@@ -4,7 +4,7 @@
  *
  * @author             Roland Haeder <webmaster@ship-simu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Core Developer Team
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.ship-simu.org
  *
@@ -56,10 +56,6 @@ class RandomNumberGenerator extends BaseFrameworkSystem {
        protected function __construct ($className = __CLASS__) {
                // Call parent constructor
                parent::__construct($className);
-
-               // Clean up a little
-               $this->removeNumberFormaters();
-               $this->removeSystemArray();
        }
 
        /**
@@ -68,7 +64,7 @@ class RandomNumberGenerator extends BaseFrameworkSystem {
         * @param       $extraInstance  An extra instance for more salt (default: null)
         * @return      $rngInstance    An instance of this random number generator
         */
-       public final static function createRandomNumberGenerator (FrameworkInterface $extraInstance = null) {
+       public static final function createRandomNumberGenerator (FrameworkInterface $extraInstance = null) {
                // Get a new instance
                $rngInstance = new RandomNumberGenerator();
 
@@ -103,7 +99,7 @@ class RandomNumberGenerator extends BaseFrameworkSystem {
                // Do we have a single server?
                if ($this->getConfigInstance()->getConfigEntry('is_single_server') == 'Y') {
                        // Then use that IP for extra security
-                       $serverIp = $this->getConfigInstance()->getServerAddress();
+                       $serverIp = $this->getConfigInstance()->detectServerAddress();
                } // END - if
 
                // Yet-another fixed salt. This is not dependend on server software or date
@@ -130,7 +126,9 @@ class RandomNumberGenerator extends BaseFrameworkSystem {
         */
        public function randomString ($length = -1) {
                // Is the number <1, then fix it to default length
-               if ($length < 1) $length = $this->rndStrLen;
+               if ($length < 1) {
+                       $length = $this->rndStrLen;
+               } // END - if
 
                // Initialize the string
                $randomString = '';
@@ -139,7 +137,7 @@ class RandomNumberGenerator extends BaseFrameworkSystem {
                for ($idx = 0; $idx < $length; $idx++) {
                        // Add a random character and add it to our string
                        $randomString .= chr($this->randomNumber(0, 255));
-               }
+               } // END - for
 
                // Return the random string a little mixed up
                return str_shuffle($randomString);
@@ -174,6 +172,24 @@ class RandomNumberGenerator extends BaseFrameworkSystem {
        public final function getFixedSalt () {
                return $this->fixedSalt;
        }
+
+       /**
+        * Generates a key based on if we have extra (default) or fixed salt enabled
+        *
+        * @return      $key    The generated key for encrypion
+        */
+       public function generateKey () {
+               // Default is extra salt
+               $key = md5($this->getExtraSalt());
+
+               // Get key
+               if ($this->getConfigInstance()->getConfigEntry('crypt_fixed_salt') == 'Y') {
+                       $key = md5($this->getFixedSalt());
+               } // END - if
+
+               // Return it
+               return $key;
+       }
 }
 
 // [EOF]