cryptal  latest
Cryptography Abstraction Layer
Pkcs7.php
1 <?php
2 
4 
6 
8 class Pkcs7 implements PaddingInterface
9 {
10  public function getPaddingData($blockSize, $expectedSize)
11  {
12  return str_repeat(chr($expectedSize), $expectedSize);
13  }
14 
15  public function getPaddingSize($paddedData, $blockSize)
16  {
17  $len = strlen($paddedData);
18  if (!$len) {
19  throw new \Exception('Invalid data');
20  }
21 
22  $padLen = ord($paddedData[$len - 1]);
23 
24  // Make sure all bytes marked as padding are the same.
25  if ($padLen - 1 !== strspn($paddedData, chr($padLen), -$padLen, -1)) {
26  throw new \Exception('Invalid data');
27  }
28 
29  return $padLen;
30  }
31 }
Pads a string using the scheme defined in PKCS#7.
Definition: Pkcs7.php:8
getPaddingData($blockSize, $expectedSize)
Definition: Pkcs7.php:10
getPaddingSize($paddedData, $blockSize)
Definition: Pkcs7.php:15