]> git.mxchange.org Git - shipsimu.git/blobdiff - inc/classes/main/crypto/class_CryptoHelper.php
More conventions than code added:
[shipsimu.git] / inc / classes / main / crypto / class_CryptoHelper.php
index 2765abddbbb163014a22046bdc09d0c8d9ddf323..0968b5271353c83b591f02c1d4fd01790ccc80b0 100644 (file)
@@ -4,7 +4,7 @@
  *
  * @author             Roland Haeder <webmaster@ship-simu.org>
  * @version            0.0.0
- * @copyright  Copyright(c) 2007, 2008 Roland Haeder, this is free software
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, this is free software
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.ship-simu.org
  *
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 class CryptoHelper extends BaseFrameworkSystem implements Cryptable {
+       // Exception constants
+       const EXCEPTION_ENCRYPT_MISSING = 0x1f0;
+       const EXCEPTION_ENCRYPT_INVALID = 0x1f1;
+
        /**
         * An instance of this own clas
         */
@@ -168,10 +172,53 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable {
                $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
 
                // Get key
-               $key = md5($this->rngInstance->getFixedSalt());
+               if ($this->getConfigInstance()->readConfig('crypt_fixed_salt') === "Y") {
+                       $key = md5($this->rngInstance->getFixedSalt());
+               } else {
+                       $key = md5($this->rngInstance->getExtraSalt());
+               }
+
+               // Add some "garbage" to the string
+               switch ($this->rngInstance->randomNumber(0, 8)) {
+                       case 0:
+                               $garbageString = crc32($this->rngInstance->randomString(10))."|".base64_encode($str)."|".crc32($this->rngInstance->randomString(20));
+                               break;
+
+                       case 1:
+                               $garbageString = crc32($this->rngInstance->randomString(10))."|".base64_encode($str)."|".md5($this->rngInstance->randomString(20));
+                               break;
+
+                       case 2:
+                               $garbageString = crc32($this->rngInstance->randomString(10))."|".base64_encode($str)."|".sha1($this->rngInstance->randomString(20));
+                               break;
+
+                       case 3:
+                               $garbageString = md5($this->rngInstance->randomString(10))."|".base64_encode($str)."|".crc32($this->rngInstance->randomString(20));
+                               break;
+
+                       case 4:
+                               $garbageString = md5($this->rngInstance->randomString(10))."|".base64_encode($str)."|".md5($this->rngInstance->randomString(20));
+                               break;
+
+                       case 5:
+                               $garbageString = md5($this->rngInstance->randomString(10))."|".base64_encode($str)."|".sha1($this->rngInstance->randomString(20));
+                               break;
+
+                       case 6:
+                               $garbageString = sha1($this->rngInstance->randomString(10))."|".base64_encode($str)."|".crc32($this->rngInstance->randomString(20));
+                               break;
+
+                       case 7:
+                               $garbageString = sha1($this->rngInstance->randomString(10))."|".base64_encode($str)."|".md5($this->rngInstance->randomString(20));
+                               break;
+
+                       case 8:
+                               $garbageString = sha1($this->rngInstance->randomString(10))."|".base64_encode($str)."|".sha1($this->rngInstance->randomString(20));
+                               break;
+               }
 
                // Encrypt the string
-               $encrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $str, MCRYPT_MODE_ECB, $iv);
+               $encrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $garbageString, MCRYPT_MODE_ECB, $iv);
 
                // Return the string
                return $encrypted;
@@ -189,10 +236,18 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable {
                $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
 
                // Get key
-               $key = md5($this->rngInstance->getFixedSalt());
+               if ($this->getConfigInstance()->readConfig('crypt_fixed_salt') === "Y") {
+                       $key = md5($this->rngInstance->getFixedSalt());
+               } else {
+                       $key = md5($this->rngInstance->getExtraSalt());
+               }
 
-               // Encrypt the string
-               $str = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $encrypted, MCRYPT_MODE_ECB, $iv);
+               // Decrypt the string
+               $garbageString = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $encrypted, MCRYPT_MODE_ECB, $iv);
+
+               // Get the real string out
+               $strArray = explode("|", $garbageString);
+               $str = base64_decode($strArray[1]);
 
                // Trim trailing nulls away
                $str = rtrim($str, "\0");