+
+ /**
+ * Encrypt the string with fixed salt
+ *
+ * @param $str The unencrypted string
+ * @return $encrypted Encrypted string
+ */
+ public function encryptString ($str) {
+ // Init crypto module
+ $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
+ $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
+
+ // Get key
+ 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, $garbageString, MCRYPT_MODE_ECB, $iv);
+
+ // Return the string
+ return $encrypted;
+ }
+
+ /**
+ * Decrypt the string with fixed salt
+ *
+ * @param $encrypted Encrypted string
+ * @return $str The unencrypted string
+ */
+ public function decryptString ($encrypted) {
+ // Init crypto module
+ $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
+ $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
+
+ // Get key
+ if ($this->getConfigInstance()->readConfig('crypt_fixed_salt') === "Y") {
+ $key = md5($this->rngInstance->getFixedSalt());
+ } else {
+ $key = md5($this->rngInstance->getExtraSalt());
+ }
+
+ // 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");
+
+ // Return the string
+ return $str;
+ }