cryptal  latest
Cryptography Abstraction Layer
CFB.php
1 <?php
2 
4 
7 
11 class CFB implements AsymmetricModeInterface
12 {
14  protected $cipher;
15 
17  protected $iv;
18 
19  public function __construct(CryptoInterface $cipher, $iv, $tagLength)
20  {
21  $ivSize = strlen($iv);
22  $blockSize = $cipher->getBlockSize();
23  if ($ivSize !== $blockSize) {
24  throw new \Exception("Invalid IV size (got $ivSize bytes; should be $blockSize)");
25  }
26 
27  $this->cipher = $cipher;
28  $this->iv = $iv;
29  }
30 
31  public function encrypt($data, $context)
32  {
33  $res = $this->cipher->encrypt('', $this->iv) ^ $data;
34  $this->iv = $res;
35  return $res;
36  }
37 
38  public function decrypt($data, $context)
39  {
40  $res = $this->cipher->encrypt('', $this->iv) ^ $data;
41  $this->iv = $data;
42  return $res;
43  }
44 }
__construct(CryptoInterface $cipher, $iv, $tagLength)
Definition: CFB.php:19
$iv
Initialization Vector.
Definition: CFB.php:17
decrypt($data, $context)
Definition: CFB.php:38
encrypt($data, $context)
Definition: CFB.php:31