Search code examples
phpphpseclibblowfish

Wrong Blowfish Symmetric Key Encryption with PHP 5.2.9 on 32-bit Linux OS


I'm trying to encrypt a string using symmetric key encryption (blowfish) with PHP 5.2.9 (on a 32-bit Linux OS) and using phpseclib 1.0.3 (running in internal mode), the sample code I'm using it's pretty simple:

include('Crypt/Blowfish.php');

$cipher = new Crypt_Blowfish();
$data = 'abcdefghijk';

$cipher->setKey('abcdef0123456789abcdefghi9876543');

echo bin2hex($cipher->encrypt($data));

the generated output is (PHP 5.2.9 - 32-bit Linux OS):

0e1651fc54dd530757fc1711b696dac5

But I've tried the same code with other servers (PHP 7.07, PHP 5.3.3, PHP 5.0.4) and ALL of them generate this (all of them are 64-bit Linux OS):

ad7145c675b1c914bbfe379dc7293bf3

I suppose that the PHP 5.2.9 output is wrong. What could be the cause of this? Any clues?


Solution

  • It was a problem related to float to int conversions on 32-bit Linux pre-PHP 5.3. Developers of phpseclib fixed the issue on version 1.0.4 & 2.0.4