Re: ecb works , but cfb and cbc don't ( php )



veg_all@xxxxxxxxx wrote:
<?php

$input = 'Hello World Today';
$key = '12345';

$td = mcrypt_module_open('rijndael-128', '', 'cbc', '');
$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND );
mcrypt_generic_init($td, $key, $iv);

$encrypted_data = mcrypt_generic($td, $input);

$decrypted = mdecrypt_generic($td, $encrypted_data );

I'm gonna go out on a limb that you have to reset the IV of the mode
first. e.g.

mcrypt_generic($td, $key, $iv);
$decrypted = mdecrypt_generic($td, $encrypted_data );

This is because your "iv" has changed from the encryption call [hint:
look up a block diagram of how CBC mode works] and you need the
original iv to begin decryption.

Same applies to other chaining modes [such as CTR, CFB and OFB mode].

Tom

.