Back to AbstractAES class

Method getZeroPadding

protected string
getZeroPadding
(mixed $string, mixed $blockSize)
Returns null bytes to append to the string so that it's zero padded to the specified block size
Parameters
  • string $string The binary string which will be zero padded
  • int $blockSize The block size
Returns
  • string The zero bytes to append to the string to zero pad it to $blockSize
Class: AbstractAES
Project: Joomla

Method getZeroPadding - Source code

/**
 * Returns null bytes to append to the string so that it's zero padded to the specified block size
 *
 * @param   string $string    The binary string which will be zero padded
 * @param   int    $blockSize The block size
 *
 * @return  string  The zero bytes to append to the string to zero pad it to $blockSize
 */
protected function getZeroPadding($string, $blockSize)
{
    $stringSize = \strlen($string);
    if (\function_exists('mb_strlen')) {
        $stringSize = mb_strlen($string, 'ASCII');
    }
    if ($stringSize == $blockSize) {
        return '';
    }
    if ($stringSize < $blockSize) {
        return str_repeat("\x00", $blockSize - $stringSize);
    }
    $paddingBytes = $stringSize % $blockSize;
    return str_repeat("\x00", $blockSize - $paddingBytes);
}