示例#1
0
 /**
  * @param JWAInterface $algorithm
  *
  * @return self
  */
 public function addAlgorithm(JWAInterface $algorithm)
 {
     if (!$this->isAlgorithmSupported($algorithm->getAlgorithmName())) {
         $this->algorithms[$algorithm->getAlgorithmName()] = $algorithm;
     }
     return $this;
 }
示例#2
0
 /**
  * @param \Jose\JWAInterface                         $key_encryption_algorithm
  * @param \Jose\Operation\ContentEncryptionInterface $content_encryption_algorithm
  * @param \Jose\JWKInterface                         $key
  * @param string|null                                $encrypted_cek
  * @param array                                      $header
  *
  * @return string
  */
 public function getCEK(JWAInterface $key_encryption_algorithm, ContentEncryptionInterface $content_encryption_algorithm, JWKInterface $key, $encrypted_cek, array $header)
 {
     if ($key_encryption_algorithm instanceof DirectEncryptionInterface) {
         return $key_encryption_algorithm->getCEK($key, $header);
     } elseif ($key_encryption_algorithm instanceof KeyAgreementInterface) {
         return $key_encryption_algorithm->getAgreementKey($content_encryption_algorithm->getCEKSize(), $key, null, $header);
     } elseif ($key_encryption_algorithm instanceof KeyAgreementWrappingInterface) {
         return $key_encryption_algorithm->unwrapAgreementKey($key, $encrypted_cek, $content_encryption_algorithm->getCEKSize(), $header);
     } elseif ($key_encryption_algorithm instanceof KeyEncryptionInterface) {
         return $key_encryption_algorithm->decryptKey($key, $encrypted_cek, $header);
     } else {
         throw new \RuntimeException('Unsupported CEK generation');
     }
 }