note 20856 modified in function.mcrypt-get-iv-size by derick

From: Date: Sun, 12 May 2002 15:46:06 +0000
Subject: note 20856 modified in function.mcrypt-get-iv-size by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-30529@lists.php.net to get a copy of this message
the above example, works, however I would like to share with you another example that derick at php.net helped me figure out: The IV needs to be the same size as the cipher/mode you are using. So we use substr() to achieve this. NOTE: This will fix your problems if you are trying to generate an IV and it is not working when you try to decrypt. The reason is that you must have the same IV (think: starting point) both at encryption and decryption stages. NOTE: This will not work when the required IV is larger than the length of the string that MD5 returns. // create IV for CAST_256 in mode CFB // from the key (which is same in both en/decrypt stages $iv = substr(md5($key), 0,mcrypt_get_iv_size (MCRYPT_CAST_256,MCRYPT_MODE_CFB)); cheers, kyle --was-- the above example, works, however I would like to share with you another example that derick at php.net helped me figure out: The IV needs to be the same size as the cipher/mode you are using. So we use substr() to achieve this. NOTE: This will fix your problems if you are trying to generate an IV and it is not working when you try to decrypt. The reason is that you must have the same IV (think: starting point) both at encryption and decryption stages. // create IV for CAST_256 in mode CFB // from the key (which is same in both en/decrypt stages $iv = substr(md5($key), 0,mcrypt_get_iv_size (MCRYPT_CAST_256,MCRYPT_MODE_CFB)); cheers, kyle http://www.php.net/manual/en/function.mcrypt-get-iv-size.php

« previous php.notes (#30529) next »