Re: ecb works , but cfb and cbc don't ( php )
- From: "Tom St Denis" <tomstdenis@xxxxxxxxx>
- Date: 22 Jul 2006 12:30:34 -0700
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
.
- Follow-Ups:
- Re: ecb works , but cfb and cbc don't ( php )
- From: veg_all
- Re: ecb works , but cfb and cbc don't ( php )
- References:
- ecb works , but cfb and cbc don't ( php )
- From: veg_all
- ecb works , but cfb and cbc don't ( php )
- Prev by Date: ecb works , but cfb and cbc don't ( php )
- Next by Date: Re: ecb works , but cfb and cbc don't ( php )
- Previous by thread: ecb works , but cfb and cbc don't ( php )
- Next by thread: Re: ecb works , but cfb and cbc don't ( php )
- Index(es):