handleKey($key); Assertion::true($key->isPrivate(), 'The key is not private'); openssl_sign($data, $signature, $key->asPem(), $this->getHashAlgorithm()); return $signature; } public function verify(string $data, Key $key, string $signature): bool { $key = $this->handleKey($key); return 1 === openssl_verify($data, $signature, $key->asPem(), $this->getHashAlgorithm()); } abstract protected function getHashAlgorithm(): int; private function handleKey(Key $key): RsaKey { return new RsaKey($key->getData()); } }