/**
  * Decrypt data with a public key.
  *
  * @param string $encryptedData
  *
  * @throws \LogicException
  *
  * @return string
  */
 protected function decrypt($encryptedData)
 {
     $publicKey = openssl_pkey_get_public($this->publicKey->getKeyPath());
     $publicKeyDetails = @openssl_pkey_get_details($publicKey);
     if ($publicKeyDetails === null) {
         throw new \LogicException(sprintf('Could not get details of public key: %s', $this->publicKey->getKeyPath()));
     }
     $chunkSize = ceil($publicKeyDetails['bits'] / 8);
     $output = '';
     $encryptedData = base64_decode($encryptedData);
     while ($encryptedData) {
         $chunk = substr($encryptedData, 0, $chunkSize);
         $encryptedData = substr($encryptedData, $chunkSize);
         if (openssl_public_decrypt($chunk, $decrypted, $publicKey) === false) {
             // @codeCoverageIgnoreStart
             throw new \LogicException('Failed to decrypt data');
             // @codeCoverageIgnoreEnd
         }
         $output .= $decrypted;
     }
     openssl_pkey_free($publicKey);
     return $output;
 }
 /**
  * Generate a JWT from the access token
  *
  * @param CryptKey $privateKey
  *
  * @return string
  */
 public function convertToJWT(CryptKey $privateKey)
 {
     return (new Builder())->setAudience($this->getClient()->getIdentifier())->setId($this->getIdentifier(), true)->setIssuedAt(time())->setNotBefore(time())->setExpiration($this->getExpiryDateTime()->getTimestamp())->setSubject($this->getUserIdentifier())->set('scopes', $this->getScopes())->sign(new Sha256(), new Key($privateKey->getKeyPath(), $privateKey->getPassPhrase()))->getToken();
 }