I'm trying pass data between applications that was encrypted using the Horde/phpmyadmin blowfish.php library, using mcrypt
instead. If I do something like:
$key = "qwerty";
$data = "12345678";
$pma_cipher = new Horde_Cipher_blowfish;
print base64_encode( mcrypt_encrypt( MCRYPT_BLOWFISH, $key, $data, MCRYPT_MODE_CBC ) );
print PMA_blowfish_encrypt( $data, $key );
print base64_encode( $pma_cipher->encryptBlock( $data, $key ) );
print base64_encode( $pma_cipher->encryptBlock( $data, $key ) );
The output is
pC+XbHWnqIg= // mcrypt
pC+XbHWnqIg= // PMA blowfish
pC+XbHWnqIg= // OK
WwkIWeYzlHw= // next block is different
Furthermore, if I change the data:
$key = "qwerty";
$data = "123456789";
$pma_cipher = new Horde_Cipher_blowfish;
print base64_encode(mcrypt_encrypt(MCRYPT_BLOWFISH, $key, $data, MCRYPT_MODE_CBC));
print PMA_blowfish_encrypt( $data, $key );
I now get:
pC+XbHWnqIjaCTiQlKkXRQ==
pC+XbHWnqIg99GXjyWLMmA==
It seems that the Horde/PMA version is changing the key every block.
Is there a way to tweak the mcrypt calls to make the two libraries cross-compatible, or should I just pick one or the other and adjust things accordingly?