Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function sign(JWKInterface $key, $input)
 {
     $this->checkKey($key);
     $values = array_intersect_key($key->getValues(), array_flip(['n', 'e', 'p', 'd', 'q', 'dp', 'dq', 'qi']));
     $rsa = RSAConverter::fromArrayToRSACrypt($values);
     if ($rsa->getPrivateKey() === false) {
         throw new \InvalidArgumentException('The key is not a private key');
     }
     $rsa->setHash($this->getAlgorithm());
     if ($this->getSignatureMethod() === PHPSecLibRSA::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;
 }