summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--system/libraries/Encrypt.php59
-rw-r--r--user_guide_src/source/libraries/encrypt.rst9
2 files changed, 14 insertions, 54 deletions
diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php
index f72bd2302..2541a4467 100644
--- a/system/libraries/Encrypt.php
+++ b/system/libraries/Encrypt.php
@@ -81,7 +81,11 @@ class CI_Encrypt {
*/
public function __construct()
{
- $this->_mcrypt_exists = function_exists('mcrypt_encrypt');
+ if (($this->_mcrypt_exists = function_exists('mcrypt_encrypt')) === FALSE)
+ {
+ show_error('The Encrypt library requires the Mcrypt extension.');
+ }
+
log_message('debug', 'Encrypt Class Initialized');
}
@@ -138,10 +142,10 @@ class CI_Encrypt {
* Encodes the message string using bitwise XOR encoding.
* The key is combined with a random hash, and then it
* too gets converted using XOR. The whole thing is then run
- * through mcrypt (if supported) using the randomized key.
- * The end result is a double-encrypted message string
- * that is randomized with each call to this function,
- * even if the supplied message and key are the same.
+ * through mcrypt using the randomized key. The end result
+ * is a double-encrypted message string that is randomized
+ * with each call to this function, even if the supplied
+ * message and key are the same.
*
* @param string the string to encode
* @param string the key
@@ -149,8 +153,7 @@ class CI_Encrypt {
*/
public function encode($string, $key = '')
{
- $method = ($this->_mcrypt_exists === TRUE) ? 'mcrypt_encode' : '_xor_encode';
- return base64_encode($this->$method($string, $this->get_key($key)));
+ return base64_encode($this->mcrypt_encode($string, $this->get_key($key)));
}
// --------------------------------------------------------------------
@@ -171,8 +174,7 @@ class CI_Encrypt {
return FALSE;
}
- $method = ($this->_mcrypt_exists === TRUE) ? 'mcrypt_decode' : '_xor_decode';
- return $this->$method(base64_decode($string), $this->get_key($key));
+ return $this->mcrypt_decode(base64_decode($string), $this->get_key($key));
}
// --------------------------------------------------------------------
@@ -194,12 +196,7 @@ class CI_Encrypt {
*/
public function encode_from_legacy($string, $legacy_mode = MCRYPT_MODE_ECB, $key = '')
{
- if ($this->_mcrypt_exists === FALSE)
- {
- log_message('error', 'Encoding from legacy is available only when Mcrypt is in use.');
- return FALSE;
- }
- elseif (preg_match('/[^a-zA-Z0-9\/\+=]/', $string))
+ if (preg_match('/[^a-zA-Z0-9\/\+=]/', $string))
{
return FALSE;
}
@@ -230,38 +227,6 @@ class CI_Encrypt {
// --------------------------------------------------------------------
/**
- * XOR Encode
- *
- * Takes a plain-text string and key as input and generates an
- * encoded bit-string using XOR
- *
- * @param string
- * @param string
- * @return string
- */
- protected function _xor_encode($string, $key)
- {
- $rand = '';
- do
- {
- $rand .= mt_rand();
- }
- while (strlen($rand) < 32);
-
- $rand = $this->hash($rand);
-
- $enc = '';
- for ($i = 0, $ls = strlen($string), $lr = strlen($rand); $i < $ls; $i++)
- {
- $enc .= $rand[($i % $lr)].($rand[($i % $lr)] ^ $string[$i]);
- }
-
- return $this->_xor_merge($enc, $key);
- }
-
- // --------------------------------------------------------------------
-
- /**
* XOR Decode
*
* Takes an encoded string and key as input and generates the
diff --git a/user_guide_src/source/libraries/encrypt.rst b/user_guide_src/source/libraries/encrypt.rst
index faff39975..6b65099a6 100644
--- a/user_guide_src/source/libraries/encrypt.rst
+++ b/user_guide_src/source/libraries/encrypt.rst
@@ -2,13 +2,8 @@
Encrypt Class
#############
-The Encrypt Class provides two-way data encryption. It uses a scheme
-that either compiles the message using a randomly hashed bitwise XOR
-encoding scheme, or is encrypted using the Mcrypt library. If Mcrypt is
-not available on your server the encoded message will still provide a
-reasonable degree of security for encrypted sessions or other such
-"light" purposes. If Mcrypt is available, you'll be provided with a high
-degree of security appropriate for storage.
+The Encrypt Class provides two-way data encryption. It encrypted using
+the Mcrypt PHP extension, which is required for the Encrypt Class to run.
.. important:: This library has been DEPRECATED and is only kept for
backwards compatibility. Please use the new :doc:`Encryption Library