|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-08-21 07:37 UTC] jinger dot jiang at autodesk dot com
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'.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 07 21:00:01 2025 UTC |
Sorry for uncomplete code, the $key is not empty. Here is the complete code: $key="testlink"; 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; }