1

I want to migrate my system from pear/Crypt/Blowfish to phpseclib/Crypt/Blowfish lib.

I need to have a total backward compatibility. So, What are differences between these two libraries ?

I found in this link that "PEAR's Crypt_Blowfish uses ECB by default, and phpseclib's uses CBC".

So I configured phpseclib to work with ECB, but is still a difference between two libs. Which one ?

Rey0bs
  • 1,192
  • 12
  • 19

1 Answers1

2

Finally I found the solution :

By default, pear crypt package uses chr(0) to padding strings wich doesn't have a length multiple of 8 (block size). But phpseclib uses integers instead.

Here is the solution :

$crypt = new Crypt_Blowfish(CRYPT_MODE_ECB);
$crypt->setKey('mysecretkey');
$crypt->disablePadding();
// You must padding your input here with chr(0),
// to put your input length to a multiple of 8
$block_size = 8;
$pad = $block_size - (strlen($text) % $block_size);
$text = str_pad($text, strlen($text) + $pad, chr(0));
$encrypted = $crypt->encrypt($text);
Rey0bs
  • 1,192
  • 12
  • 19