Ejemplo n.º 1
0
 /**
  * Initialize key management algorithm from a JWK and a header.
  *
  * @param JWK $jwk
  * @param Header $header
  * @return KeyManagementAlgorithm
  */
 public static function fromJWK(JWK $jwk, Header $header)
 {
     $factory = new KeyAlgorithmFactory($header);
     return $factory->algoByKey($jwk);
 }
Ejemplo n.º 2
0
Archivo: JWE.php Proyecto: sop/jwx
 /**
  * Decrypt content using a key from the given JWK set.
  *
  * Correct key shall be sought by the key ID indicated by the header.
  *
  * @param JWKSet $set Set of JSON Web Keys
  * @throws \RuntimeException If algorithm initialization fails
  * @return string Plaintext payload
  */
 public function decryptWithJWKSet(JWKSet $set)
 {
     if (!count($set)) {
         throw new \RuntimeException("No keys.");
     }
     $header = $this->header();
     $factory = new KeyAlgorithmFactory($header);
     $key_algo = $factory->algoByKeys($set);
     $enc_algo = EncryptionAlgorithmFactory::algoByHeader($header);
     return $this->decrypt($key_algo, $enc_algo);
 }