randomizer = new Randomizer(); } /** * @return array{alg: string, ext: bool, k: string, key_ops: list, kty: string} */ public function generateKey(string $algo = StoredObjectManagerInterface::ALGORITHM): array { if (StoredObjectManagerInterface::ALGORITHM !== $algo) { throw new \LogicException(sprintf("Algorithm '%s' is not supported.", $algo)); } $key = $this->randomizer->getBytes(32); return [ 'alg' => 'A256CBC', 'ext' => true, 'k' => Base64Url::encode($key), 'key_ops' => ['encrypt', 'decrypt'], 'kty' => 'oct', ]; } /** * @return list> */ public function generateIv(): array { $iv = []; for ($i = 0; $i < 16; ++$i) { $iv[] = unpack('C', $this->randomizer->getBytes(8))[1]; } return $iv; } }