for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace MiladRahimi\Jwt\Cryptography\Keys;
use MiladRahimi\Jwt\Exceptions\InvalidKeyException;
class RsaPublicKey
{
/**
* @var mixed Key resource handler
*/
protected $resource;
protected ?string $id;
* @param string $key Key file path or string content
* @param string|null $id Key identifier
*
* @throws InvalidKeyException
public function __construct(string $key, ?string $id = null)
$content = realpath($key) ? file_get_contents(realpath($key)) : $key;
$this->resource = openssl_pkey_get_public($content);
if ($this->resource === false) {
throw new InvalidKeyException(openssl_error_string() ?: '');
}
$this->id = $id;
* @return mixed
public function getResource()
return $this->resource;
public function getId(): ?string
return $this->id;