Exemple #1
0
 /**
  * Initialize from a PublicKey object.
  *
  * @param PublicKey $pub_key Public key
  * @throws \UnexpectedValueException
  * @return self
  */
 public static function fromPublicKey(PublicKey $pub_key)
 {
     if ($pub_key instanceof RSAPublicKey) {
         return RSAPublicKeyJWK::fromRSAPublicKey($pub_key);
     }
     if ($pub_key instanceof ECPublicKey) {
         return ECPublicKeyJWK::fromECPublicKey($pub_key);
     }
     throw new \UnexpectedValueException("Unsupported public key.");
 }
Exemple #2
0
 /**
  *
  * @param JWK $jwk
  * @param Header $header
  * @throws \UnexpectedValueException
  * @return RSASSAPKCS1Algorithm
  */
 public static function fromJWK(JWK $jwk, Header $header)
 {
     $alg = JWA::deriveAlgorithmName($header, $jwk);
     if (!array_key_exists($alg, self::MAP_ALGO_TO_CLASS)) {
         throw new \UnexpectedValueException("Unsupported algorithm '{$alg}'.");
     }
     $cls = self::MAP_ALGO_TO_CLASS[$alg];
     if ($jwk->has(...RSAPrivateKeyJWK::MANAGED_PARAMS)) {
         return $cls::fromPrivateKey(RSAPrivateKeyJWK::fromJWK($jwk));
     }
     return $cls::fromPublicKey(RSAPublicKeyJWK::fromJWK($jwk));
 }