├── .github ├── FUNDING.yml ├── PULL_REQUEST_TEMPLATE.md └── CONTRIBUTING.md ├── README.md ├── HS256.php ├── HS384.php ├── HS512.php ├── composer.json ├── LICENSE └── HMAC.php /.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 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | HMAC Based Signature Algorithms For JWT-Framework 2 | ================================================= 3 | 4 | This repository is a sub repository of [the JWT Framework](https://github.com/web-token/jwt-framework) project and is READ ONLY. 5 | 6 | **Please do not submit any Pull Request here.** 7 | You should go to [the main repository](https://github.com/web-token/jwt-framework) instead. 8 | 9 | # Documentation 10 | 11 | The official documentation is available as https://web-token.spomky-labs.com/ 12 | 13 | # Licence 14 | 15 | This software is release under [MIT licence](LICENSE). 16 | -------------------------------------------------------------------------------- /HS256.php: -------------------------------------------------------------------------------- 1 | =8.1", 24 | "web-token/jwt-signature": "^3.0" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2019 Spomky-Labs 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /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 | --------------------------------------------------------------------------------