/** * @param array $values * * @return \phpseclib\Crypt\RSA */ private function getRsaObject(array $values) { $rsa = KeyConverter::fromArrayToRSACrypt($values); $encryption_mode = $this->getEncryptionMode(); $rsa->setEncryptionMode($encryption_mode); if (PHPSecLibRSA::ENCRYPTION_OAEP === $encryption_mode) { $rsa->setHash($this->getHashAlgorithm()); $rsa->setMGFHash($this->getHashAlgorithm()); } return $rsa; }
/** * {@inheritdoc} */ public function sign(JWKInterface $key, $input) { $this->checkKey($key); $values = array_intersect_key($key->getAll(), array_flip(['n', 'e', 'p', 'd', 'q', 'dp', 'dq', 'qi'])); $rsa = KeyConverter::fromArrayToRSACrypt($values); if ($rsa->getPrivateKey() === false) { throw new \InvalidArgumentException('The key is not a private key'); } $rsa->setHash($this->getAlgorithm()); if ($this->getSignatureMethod() === \phpseclib\Crypt\RSA::SIGNATURE_PSS) { $rsa->setMGFHash($this->getAlgorithm()); $rsa->setSaltLength(0); } $rsa->setSignatureMode($this->getSignatureMethod()); $result = $rsa->sign($input); if ($result === false) { throw new \RuntimeException('An error occurred during the creation of the signature'); } return $result; }