Example #1
0
 /**
  * Signs the data
  *
  * @param Signer $signer
  * @param string $key
  *
  * @return Builder
  */
 public function sign(Signer $signer, $key)
 {
     $signer->modifyHeader($this->headers);
     $this->signature = $signer->sign($this->getToken()->getPayload(), $key);
     return $this;
 }
Example #2
0
 /**
  * Verify if the key matches with the one that created the signature
  *
  * @param Signer $signer
  * @param string $key
  *
  * @return boolean
  *
  * @throws BadMethodCallException When token is not signed
  */
 public function verify(Signer $signer, $key)
 {
     if ($this->signature === null) {
         throw new BadMethodCallException('This token is not signed');
     }
     if ($this->headers['alg'] !== $signer->getAlgorithmId()) {
         return false;
     }
     return $this->signature->verify($signer, $this->getPayload(), $key);
 }