[-] Classes : #PSCFI-3880 : BugFix mbstring overload on Rijndael encrypt-decrypt
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@11019 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
+15
-4
@@ -39,16 +39,27 @@ class RijndaelCore
|
||||
// Base64 is not required, but it is be more compact than urlencode
|
||||
public function encrypt($plaintext)
|
||||
{
|
||||
if (($length = strlen($plaintext)) >= 1048576)
|
||||
$length = (ini_get('mbstring.func_overload') & 2) ? mb_strlen($plaintext, ini_get('default_charset')) : strlen($plaintext);
|
||||
|
||||
if ($length >= 1048576)
|
||||
return false;
|
||||
return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $this->_key, $plaintext, MCRYPT_MODE_ECB, $this->_iv)).sprintf('%06d', $length);
|
||||
}
|
||||
|
||||
public function decrypt($ciphertext)
|
||||
{
|
||||
$plainTextLength = intval(substr($ciphertext, -6));
|
||||
$ciphertext = substr($ciphertext, 0, -6);
|
||||
return substr(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $this->_key, base64_decode($ciphertext), MCRYPT_MODE_ECB, $this->_iv), 0, $plainTextLength);
|
||||
if (ini_get('mbstring.func_overload') & 2)
|
||||
{
|
||||
$plainTextLength = intval(mb_substr($ciphertext, -6, 6, ini_get('default_charset')));
|
||||
$ciphertext = mb_substr($ciphertext, 0, -6, ini_get('default_charset'));
|
||||
return mb_substr(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $this->_key, base64_decode($ciphertext), MCRYPT_MODE_ECB, $this->_iv), 0, $plainTextLength, ini_get('default_charset'));
|
||||
}
|
||||
else
|
||||
{
|
||||
$plainTextLength = intval(substr($ciphertext, -6));
|
||||
$ciphertext = substr($ciphertext, 0, -6);
|
||||
return substr(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $this->_key, base64_decode($ciphertext), MCRYPT_MODE_ECB, $this->_iv), 0, $plainTextLength);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user