コード例 #1
0
ファイル: DirectCEKAlgorithm.php プロジェクト: sop/jwx
 /**
  *
  * @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());
 }
コード例 #2
0
ファイル: AESKWAlgorithm.php プロジェクト: sop/jwx
 /**
  *
  * @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());
 }
コード例 #3
0
ファイル: PBES2Algorithm.php プロジェクト: sop/jwx
 /**
  *
  * @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);
 }