From:             jinger dot jiang at autodesk dot com
Operating system: Vista, Windows2003
PHP version:      5.2.10
PHP Bug Type:     mcrypt related
Bug description:  The encryption function 'mcrypt_cfb(..)' to failed encrypt 
password 'Zx57Kl36'

Description:
------------
I use the function mcrypt_cfb(..,MCRYPT_ENCRYPT,.) to encrypt a password
valued 'Zx57Kl36', then I use mcrypt_cfb(..,MCRYPT_DECRYPT,..) to decrypt
the value, it changed to 'Zx57Kl3'.
I also have tried 'Zx57Kl32', 'Zx57Kl34' and 'Zx57Kl35', these value is
changed to 'Zx57Kl3' too after decrypt. But 'Zx57Kl30', 'Zx57Kl31' etc are
correct after decrypt.



Reproduce code:
---------------
My code:
//$plain_text can be 'Zx57Kl36' etc.
function encrypt($plain_text) {
    $plain_text = trim($plain_text);
    $iv = substr(md5($key), 0,mcrypt_get_iv_size
(MCRYPT_CAST_256,MCRYPT_MODE_CFB));
    $c_t = mcrypt_cfb (MCRYPT_CAST_256, $key, $plain_text, MCRYPT_ENCRYPT,
$iv);
    $ret = trim(chop(base64_encode($c_t)));
    return $ret;
}

function decrypt($c_t) {
    $c_t =  trim(chop(base64_decode($c_t)));
    $iv = substr(md5($key), 0,mcrypt_get_iv_size
(MCRYPT_CAST_256,MCRYPT_MODE_CFB));
    $p_t = mcrypt_cfb (MCRYPT_CAST_256, $key, $c_t, MCRYPT_DECRYPT, $iv);
    $ret = trim(chop($p_t));
    return $ret;
}


Expected result:
----------------
$ret=encrypt('Zx57Kl36');
$ret=decrypt($ret);
then $ret should be 'Zx57Kl36' but not 'Zx57Kl3'.


Actual result:
--------------
$ret=encrypt('Zx57Kl36');
$ret=decrypt($ret);
$ret equals to 'Zx57Kl3'. It should be 'Zx57Kl36'.



-- 
Edit bug report at http://bugs.php.net/?id=49317&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=49317&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=49317&r=trysnapshot53
Try a snapshot (PHP 6.0):            
http://bugs.php.net/fix.php?id=49317&r=trysnapshot60
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=49317&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=49317&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=49317&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=49317&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=49317&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=49317&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=49317&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=49317&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=49317&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=49317&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=49317&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=49317&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=49317&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=49317&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=49317&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=49317&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=49317&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=49317&r=mysqlcfg

Reply via email to