You are here: Re: [PHP] PKCS#5 padding « PHP « IT news, forums, messages
Re: [PHP] PKCS#5 padding

Posted by Robin Vickery on 12/09/05 15:56

On 12/9/05, Binay(Local) <binay@oliveinternet.com> 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);
}

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация