On 12/9/05, Binay(Local) <[EMAIL PROTECTED]> wrote:
> Hi All
>
> Has anybody got the working code to apply the PKCS#5 padding to the text for
> encryption. Please let me know as it seems PHP inbuilt functions do not
> support this padding at all. Been worried about from past 2 days. Help me out.
The pad function simply returns the text padded to the blocksize.
The unpad function returns the unpadded text, or false if the padding
isn't valid.
function pkcs5_pad ($text, $blocksize)
{
$pad = $blocksize - (strlen($text) % $blocksize);
return $text . str_repeat(chr($pad), $pad);
}
function pkcs5_unpad ($text)
{
$pad = ord($text{strlen($text)-1});
if ($pad > strlen($text)) return false;
if (!strspn($text, chr($pad), strlen($text) - $pad)) return false;
return substr($text, 0, -1 * $pad);
}
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php