├── .github ├── CONTRIBUTING.md ├── FUNDING.yml └── PULL_REQUEST_TEMPLATE.md ├── HMAC.php ├── HS256.php ├── HS384.php ├── HS512.php ├── LICENSE ├── README.md └── composer.json /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | This repository is a sub repository of [the JWT Framework](https://github.com/web-token/jwt-framework) project and is READ ONLY. 4 | Please do not submit any Pull Requests here. It will be automatically closed. 5 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | patreon: FlorentMorselli 2 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Please do not submit any Pull Requests here. It will be automatically closed. 2 | 3 | You should submit it here: https://github.com/web-token/jwt-framework/pulls 4 | -------------------------------------------------------------------------------- /HMAC.php: -------------------------------------------------------------------------------- 1 | hash($key, $input), $signature); 23 | } 24 | 25 | public function hash(JWK $key, string $input): string 26 | { 27 | $k = $this->getKey($key); 28 | 29 | return hash_hmac($this->getHashAlgorithm(), $input, $k, true); 30 | } 31 | 32 | protected function getKey(JWK $key): string 33 | { 34 | if (! in_array($key->get('kty'), $this->allowedKeyTypes(), true)) { 35 | throw new InvalidArgumentException('Wrong key type.'); 36 | } 37 | if (! $key->has('k')) { 38 | throw new InvalidArgumentException('The key parameter "k" is missing.'); 39 | } 40 | $k = $key->get('k'); 41 | if (! is_string($k)) { 42 | throw new InvalidArgumentException('The key parameter "k" is invalid.'); 43 | } 44 | 45 | return Base64UrlSafe::decode($k); 46 | } 47 | 48 | abstract protected function getHashAlgorithm(): string; 49 | } 50 | -------------------------------------------------------------------------------- /HS256.php: -------------------------------------------------------------------------------- 1 | =8.1", 24 | "web-token/jwt-signature": "^3.0" 25 | } 26 | } 27 | --------------------------------------------------------------------------------