/** * * @param JWK $jwk * @param Header $header * @throws \UnexpectedValueException * @return self */ public static function fromJWK(JWK $jwk, Header $header) { $jwk = SymmetricKeyJWK::fromJWK($jwk); $alg = JWA::deriveAlgorithmName($header); if ($alg != JWA::ALGO_DIR) { throw new \UnexpectedValueException("Invalid algorithm '{$alg}'."); } return new self($jwk->key()); }
/** * * @param JWK $jwk * @param Header $header * @throws \UnexpectedValueException * @return AESKWAlgorithm */ public static function fromJWK(JWK $jwk, Header $header) { $jwk = SymmetricKeyJWK::fromJWK($jwk); $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]; return new $cls($jwk->key()); }
/** * * @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)); }
/** * Get signature algorithm by given JWK. * * @param JWK $jwk * @return SignatureAlgorithm */ public function algoByKey(JWK $jwk) { $alg = JWA::deriveAlgorithmName($this->_header, $jwk); $cls = self::_algoClassByName($alg); return $cls::fromJWK($jwk, $this->_header); }
/** * * @param JWK $jwk * @param Header $header * @throws \UnexpectedValueException * @return PBES2Algorithm */ public static function fromJWK(JWK $jwk, Header $header) { $jwk = SymmetricKeyJWK::fromJWK($jwk); if (!$header->hasPBES2SaltInput()) { throw new \UnexpectedValueException("No salt input."); } $salt_input = $header->PBES2SaltInput()->saltInput(); if (!$header->hasPBES2Count()) { throw new \UnexpectedValueException("No iteration count."); } $count = $header->PBES2Count()->value(); $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]; return new $cls($jwk->key(), $salt_input, $count); }