3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Crypt\Symmetric\Padding
;
15 class Pkcs7
implements PaddingInterface
19 * Pad the string to the specified size
21 * @param string $string The string to pad
22 * @param int $blockSize The size to pad to
24 * @return string The padded string
26 public function pad($string, $blockSize = 32)
28 $pad = $blockSize - (strlen($string) %
$blockSize);
29 return $string . str_repeat(chr($pad), $pad);
33 * Strip the padding from the supplied string
35 * @param string $string The string to trim
37 * @return string The unpadded string
39 public function strip($string)
41 $end = substr($string, -1);
43 $len = strlen($string) - $last;
44 if (substr($string, $len) == str_repeat($end, $last)) {
45 return substr($string, 0, $len);