/** * Initialize from the parts of a compact serialization. * * @param array $parts * @throws \UnexpectedValueException * @return self */ public static function fromParts(array $parts) { if (count($parts) != 3) { throw new \UnexpectedValueException("Invalid JWS compact serialization."); } $header = Header::fromJSON(Base64::urlDecode($parts[0])); $b64 = $header->hasB64Payload() ? $header->B64Payload()->value() : true; $payload = $b64 ? Base64::urlDecode($parts[1]) : $parts[1]; $signature_input = $parts[0] . "." . $parts[1]; $signature = Base64::urlDecode($parts[2]); return new self($header, $payload, $signature_input, $signature); }
/** * Get JWT header. * * @return JOSE */ public function header() { $header = Header::fromJSON(Base64::urlDecode($this->_parts[0])); return new JOSE($header); }
/** * Initialize from parts of compact serialization. * * @param array $parts * @throws \UnexpectedValueException * @return self */ public static function fromParts(array $parts) { if (count($parts) != 5) { throw new \UnexpectedValueException("Invalid JWE compact serialization."); } $header = Header::fromJSON(Base64::urlDecode($parts[0])); $encrypted_key = Base64::urlDecode($parts[1]); $iv = Base64::urlDecode($parts[2]); $ciphertext = Base64::urlDecode($parts[3]); $auth_tag = Base64::urlDecode($parts[4]); return new self($header, $encrypted_key, $iv, $ciphertext, $auth_tag); }