public static function setUpBeforeClass()
 {
     $jose = Jose::getInstance();
     //We define the audience
     $jose->getConfiguration()->set('audience', 'My service');
     //We use all algorithms, including none
     $jose->getConfiguration()->set('algorithms', ['HS256', 'HS384', 'HS512', 'ES256', 'ES384', 'ES512', 'none', 'RS256', 'RS384', 'RS512', 'PS256', 'PS384', 'PS512', 'A128GCM', 'A192GCM', 'A256GCM', 'A128CBC-HS256', 'A192CBC-HS384', 'A256CBC-HS512', 'A128KW', 'A192KW', 'A256KW', 'A128GCMKW', 'A192GCMKW', 'A256GCMKW', 'dir', 'ECDH-ES', 'ECDH-ES+A128KW', 'ECDH-ES+A192KW', 'ECDH-ES+A256KW', 'PBES2-HS256+A128KW', 'PBES2-HS384+A192KW', 'PBES2-HS512+A256KW', 'RSA1_5', 'RSA-OAEP', 'RSA-OAEP-256']);
     $jose->getKeysetManager()->loadKeyFromValues('My EC Key', ['kid' => 'My EC Key', 'kty' => 'EC', 'crv' => 'P-256', 'x' => 'f83OJ3D2xF1Bg8vub9tLe1gHMzV76e8Tus9uPHvRVEU', 'y' => 'x_FEzRu9m36HLN_tue659LNpXW6pCyStikYjKIWI5a0', 'd' => 'jpsQnnGQmL-YBIffH1136cspYG6-0iY7X1fCE9-E9LI']);
     $jose->getKeysetManager()->loadKeyFromValues('7', ['kty' => 'oct', 'k' => 'GawgguFyGrWKav7AX4VKUg']);
     $jose->getKeysetManager()->loadKeyFromValues('My RSA Key', RSAConverter::loadKeyFromFile(__DIR__ . '/Keys/RSA/private.key', 'tests'));
 }
Beispiel #2
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;
 }