Example #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);
 }
Example #2
0
File: JWE.php Project: 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);
 }