Server IP : 66.29.132.124 / Your IP : 18.116.87.10 Web Server : LiteSpeed System : Linux business141.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64 User : wavevlvu ( 1524) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/wavevlvu/book24.ng/vendor/namshi/jose/src/Namshi/JOSE/Signer/OpenSSL/ |
Upload File : |
<?php namespace Namshi\JOSE\Signer\OpenSSL; use InvalidArgumentException; use Namshi\JOSE\Signer\SignerInterface; use RuntimeException; /** * Class responsible to sign inputs with the a public key algorithm, after hashing it. */ abstract class PublicKey implements SignerInterface { /** * {@inheritdoc} */ public function sign($input, $key, $password = null) { $keyResource = $this->getKeyResource($key, $password); if (!$this->supportsKey($keyResource)) { throw new InvalidArgumentException('Invalid key supplied.'); } $signature = null; openssl_sign($input, $signature, $keyResource, $this->getHashingAlgorithm()); return $signature; } /** * {@inheritdoc} */ public function verify($key, $signature, $input) { $keyResource = $this->getKeyResource($key); if (!$this->supportsKey($keyResource)) { throw new InvalidArgumentException('Invalid key supplied.'); } $result = openssl_verify($input, $signature, $keyResource, $this->getHashingAlgorithm()); if ($result === -1) { throw new RuntimeException('Unknown error during verification.'); } return (bool) $result; } /** * Converts a string representation of a key into an OpenSSL resource. * * @param string|resource $key * @param string $password * * @return resource OpenSSL key resource */ protected function getKeyResource($key, $password = null) { if (is_resource($key)) { return $key; } $resource = openssl_pkey_get_public($key) ?: openssl_pkey_get_private($key, $password); if ($resource === false) { throw new RuntimeException('Could not read key resource: ' . openssl_error_string()); } return $resource; } /** * Check if the key is supported by this signer. * * @param resource $key Public or private key * * @return bool */ protected function supportsKey($key) { // OpenSSL 0.9.8+ $keyDetails = openssl_pkey_get_details($key); return isset($keyDetails['type']) ? $this->getSupportedPrivateKeyType() === $keyDetails['type'] : false; } /** * Returns the hashing algorithm used in this signer. * * @return string */ abstract protected function getHashingAlgorithm(); /** * Returns the private key type supported in this signer. * * @return string */ abstract protected function getSupportedPrivateKeyType(); }