note 54734 added to function.mcrypt-decrypt

From: Date: Thu, 14 Jul 2005 01:26:39 +0000
Subject: note 54734 added to function.mcrypt-decrypt
Groups: php.notes 
Request: Send a blank email to php-notes+get-91927@lists.php.net to get a copy of this message
It appears that mcrypt_decrypt pads the *RETURN STRING* with nulls ('\0') to fill out to n * blocksize. For old C-programmers, like myself, it is easy to believe the string ends at the first null. In PHP it does not: strlen("abc\0\0") returns 5 and *NOT* 3 strcmp("abc", "abc\0\0") returns -2 and *NOT* 0 I learned this lesson painfully when I passed a string returned from mycrypt_decrypt into a NuSoap message, which happily passed the nulls along to the receiver, who couldn't figure out what I was talking about. My solution was: $retval = mcrypt_decrypt( ...etc ...); $retval = rtrim($retval, '\0'); // trim ONLY the nulls at the END ---- My comments are based on PHP 4.3.4 ---- Manual Page -- http://www.php.net/manual/en/function.mcrypt-decrypt.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54734 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54734&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54734&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54734&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54734&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54734&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54734&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54734&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#91927) next »