// Fix Blowfish for autoload
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@11022 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
1 parent
c8fc8d1733
commit
f6cf5ff6ed
1 file changed
+48
-50
+48
-50
@@ -28,6 +28,54 @@
|
|||||||
define('PS_UNPACK_NATIVE', 1);
|
define('PS_UNPACK_NATIVE', 1);
|
||||||
define('PS_UNPACK_MODIFIED', 2);
|
define('PS_UNPACK_MODIFIED', 2);
|
||||||
|
|
||||||
|
class BlowfishCore extends Crypt_Blowfish
|
||||||
|
{
|
||||||
|
function encrypt($plaintext)
|
||||||
|
{
|
||||||
|
if (($length = strlen($plaintext)) >= 1048576)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
$ciphertext = '';
|
||||||
|
$paddedtext = $this->maxi_pad($plaintext);
|
||||||
|
$strlen = strlen($paddedtext);
|
||||||
|
for($x = 0; $x < $strlen; $x += 8)
|
||||||
|
{
|
||||||
|
$piece = substr($paddedtext, $x, 8);
|
||||||
|
$cipher_piece = parent::encrypt($piece);
|
||||||
|
$encoded = base64_encode($cipher_piece);
|
||||||
|
$ciphertext = $ciphertext.$encoded;
|
||||||
|
}
|
||||||
|
return $ciphertext.sprintf('%06d', $length);
|
||||||
|
}
|
||||||
|
|
||||||
|
function decrypt($ciphertext)
|
||||||
|
{
|
||||||
|
$plainTextLength = intval(substr($ciphertext, -6));
|
||||||
|
$ciphertext = substr($ciphertext, 0, -6);
|
||||||
|
|
||||||
|
$plaintext = '';
|
||||||
|
$chunks = explode('=', $ciphertext);
|
||||||
|
$ending_value = sizeof($chunks) ;
|
||||||
|
for($counter = 0; $counter < ($ending_value - 1); $counter++)
|
||||||
|
{
|
||||||
|
$chunk = $chunks[$counter].'=';
|
||||||
|
$decoded = base64_decode($chunk);
|
||||||
|
$piece = parent::decrypt($decoded);
|
||||||
|
$plaintext = $plaintext.$piece;
|
||||||
|
}
|
||||||
|
return substr($plaintext, 0, $plainTextLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
function maxi_pad($plaintext)
|
||||||
|
{
|
||||||
|
$str_len = sizeof($plaintext);
|
||||||
|
$pad_len = $str_len % 8;
|
||||||
|
for($x = 0; $x < $pad_len; $x++)
|
||||||
|
$plaintext = $plaintext.' ';
|
||||||
|
return $plaintext;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class Crypt_Blowfish
|
class Crypt_Blowfish
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -432,53 +480,3 @@ class Crypt_Blowfish
|
|||||||
return array('1' => $this->myUnpackN($str), '2' => $this->myUnpackN(substr($str, 4)));
|
return array('1' => $this->myUnpackN($str), '2' => $this->myUnpackN(substr($str, 4)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class BlowfishCore extends Crypt_Blowfish
|
|
||||||
{
|
|
||||||
function encrypt($plaintext)
|
|
||||||
{
|
|
||||||
if (($length = strlen($plaintext)) >= 1048576)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
$ciphertext = '';
|
|
||||||
$paddedtext = $this->maxi_pad($plaintext);
|
|
||||||
$strlen = strlen($paddedtext);
|
|
||||||
for($x = 0; $x < $strlen; $x += 8)
|
|
||||||
{
|
|
||||||
$piece = substr($paddedtext, $x, 8);
|
|
||||||
$cipher_piece = parent::encrypt($piece);
|
|
||||||
$encoded = base64_encode($cipher_piece);
|
|
||||||
$ciphertext = $ciphertext.$encoded;
|
|
||||||
}
|
|
||||||
return $ciphertext.sprintf('%06d', $length);
|
|
||||||
}
|
|
||||||
|
|
||||||
function decrypt($ciphertext)
|
|
||||||
{
|
|
||||||
$plainTextLength = intval(substr($ciphertext, -6));
|
|
||||||
$ciphertext = substr($ciphertext, 0, -6);
|
|
||||||
|
|
||||||
$plaintext = '';
|
|
||||||
$chunks = explode('=', $ciphertext);
|
|
||||||
$ending_value = sizeof($chunks) ;
|
|
||||||
for($counter = 0; $counter < ($ending_value - 1); $counter++)
|
|
||||||
{
|
|
||||||
$chunk = $chunks[$counter].'=';
|
|
||||||
$decoded = base64_decode($chunk);
|
|
||||||
$piece = parent::decrypt($decoded);
|
|
||||||
$plaintext = $plaintext.$piece;
|
|
||||||
}
|
|
||||||
return substr($plaintext, 0, $plainTextLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
function maxi_pad($plaintext)
|
|
||||||
{
|
|
||||||
$str_len = sizeof($plaintext);
|
|
||||||
$pad_len = $str_len % 8;
|
|
||||||
for($x = 0; $x < $pad_len; $x++)
|
|
||||||
$plaintext = $plaintext.' ';
|
|
||||||
return $plaintext;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Reference in new issue
Block a user