Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

I tried getting help on StackOverflow http://stackoverflow.com/questions/14550195/crypto-between-erlang-and-php but it was mostly me talking to myself :(

I tried getting help on StackOverflow https://stackoverflow.com/questions/14550195/crypto-between-erlang-and-php but it was mostly me talking to myself :(

Tweeted twitter.com/#!/StackSecurity/status/297919597355610112
Typo
Source Link
$Crypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $Key, $Text, 'ncfb', $IV);

$UnCrypt$Decrypt = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $Key, $Crypt, 'ncfb', $IV);
$Crypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $Key, $Text, 'ncfb', $IV);

$UnCrypt = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $Key, $Crypt, 'ncfb', $IV);
$Crypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $Key, $Text, 'ncfb', $IV);

$Decrypt = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $Key, $Crypt, 'ncfb', $IV);
Added details of fix.
Source Link

Update 2 - it works

Thanks to Tom Leek for his answer.

The CFB mode of mycrypt for Rijndael uses a 8-bit feedback loop and not a feedback loop the length of the key/iv.

You have to force it to use the full length with the parameter ncfb. Confusingly this is not a documented constant in the PHP Mcrypt library: http://www.php.net/manual/en/mcrypt.constants.php

The appropriate lines in the PHP now looks like this:

$Crypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $Key, $Text, 'ncfb', $IV);

$UnCrypt = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $Key, $Crypt, 'ncfb', $IV);

Update 2 - it works

Thanks to Tom Leek for his answer.

The CFB mode of mycrypt for Rijndael uses a 8-bit feedback loop and not a feedback loop the length of the key/iv.

You have to force it to use the full length with the parameter ncfb. Confusingly this is not a documented constant in the PHP Mcrypt library: http://www.php.net/manual/en/mcrypt.constants.php

The appropriate lines in the PHP now looks like this:

$Crypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $Key, $Text, 'ncfb', $IV);

$UnCrypt = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $Key, $Crypt, 'ncfb', $IV);
Update in response to comment
Source Link
Loading
Correction to text
Source Link
Loading
Source Link
Loading