{"id":15490105,"url":"https://github.com/tmilos/jose-jwt","last_synced_at":"2025-07-11T17:45:50.905Z","repository":{"id":57070666,"uuid":"49583077","full_name":"tmilos/jose-jwt","owner":"tmilos","description":"Javascript Object Signing and Encryption PHP library, supporting signed JSON Web Tokens JWT and encrypted JSON Web Encryption JWE","archived":false,"fork":false,"pushed_at":"2018-09-04T11:29:21.000Z","size":110,"stargazers_count":7,"open_issues_count":3,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-19T09:04:22.630Z","etag":null,"topics":["jose-jwt","jwt","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tmilos.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-13T15:38:12.000Z","updated_at":"2023-10-31T10:55:12.000Z","dependencies_parsed_at":"2022-08-24T10:41:14.457Z","dependency_job_id":null,"html_url":"https://github.com/tmilos/jose-jwt","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmilos%2Fjose-jwt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmilos%2Fjose-jwt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmilos%2Fjose-jwt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmilos%2Fjose-jwt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tmilos","download_url":"https://codeload.github.com/tmilos/jose-jwt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250306619,"owners_count":21408925,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["jose-jwt","jwt","php"],"created_at":"2024-10-02T07:09:20.569Z","updated_at":"2025-04-22T19:05:32.704Z","avatar_url":"https://github.com/tmilos.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jose-jwt\nJavascript Object Signing and Encryption JOSE PHP library, supporting JSON Web Tokens JWT and JSON Web Encryption JWE.\n\n[![Author](http://img.shields.io/badge/author-@tmilos-blue.svg?style=flat-square)](https://twitter.com/tmilos77)\n[![License](https://img.shields.io/packagist/l/tmilos/jose-jwt.svg)](https://packagist.org/packages/tmilos/jose-jwt)\n[![Build Status](https://travis-ci.org/tmilos/jose-jwt.svg?branch=master)](https://travis-ci.org/tmilos/jose-jwt)\n[![Coverage Status](https://coveralls.io/repos/tmilos/jose-jwt/badge.svg?branch=master\u0026service=github)](https://coveralls.io/github/tmilos/jose-jwt?branch=master)\n[![HHVM Status](http://hhvm.h4cc.de/badge/tmilos/jose-jwt.svg)](http://hhvm.h4cc.de/package/tmilos/jose-jwt)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/tmilos/jose-jwt/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/tmilos/jose-jwt/?branch=master)\n\n## JWT algorithms\n\nSupported signing algorithms\n\n| JWS Algorithm    |\n| ---------------- |\n| none             |\n| HS256            |\n| HS384            |\n| HS512            |\n| RS256            |\n| RS384            |\n| RS512            |\n\n\n## JWE algorithms and encryptions\n\nSupported JWE algorithms\n\n| JWE Algorithm    |\n| ---------------- |\n| RSA1_5           |\n| RSA-OAEP         |\n| A128KW           |\n| A192KW           |\n| A256KW           |\n| dir              |\n\n\nSupported JWE encryption\n\n| JWE Encryption   |\n| ---------------- |\n| A128CBC-HS256    |\n| A192CBC-HS384    |\n| A256CBC-HS512    |\n\n\n## JWT API\n\n```php\n$factory = new \\Tmilos\\JoseJwt\\Context\\DefaultContextFactory();\n$context = $factory-\u003eget();\n\n$payload = ['msg' =\u003e 'Hello!'];\n$extraHeader = ['iam'=\u003e'my-id'];\n\n// plain (no signature) token\n$token = \\Tmilos\\JoseJwt\\Jwt::encode($context, $payload, null, \\Tmilos\\JoseJwt\\Jws\\JwsAlgorithm::NONE, $extraHeader);\n\n// HS256 signature\n$secret = '...'; // 256 bits secret\n$token = \\Tmilos\\JoseJwt\\Jwt::encode($context, $payload, $secret, \\Tmilos\\JoseJwt\\Jws\\JwsAlgorithm::HS256, $extraHeader);\n\n// HS384 signature\n$secret = '...'; // 256 bits secret\n$token = \\Tmilos\\JoseJwt\\Jwt::encode($context, $payload, $secret, \\Tmilos\\JoseJwt\\Jws\\JwsAlgorithm::HS384, $extraHeader);\n\n// HS512 signature\n$secret = '...'; // 256 bits secret\n$token = \\Tmilos\\JoseJwt\\Jwt::encode($context, $payload, $secret, \\Tmilos\\JoseJwt\\Jws\\JwsAlgorithm::HS512, $extraHeader);\n\n// RS256\n$privateKey = openssl_get_privatekey($filename);\n$token = \\Tmilos\\JoseJwt\\Jwt::encode($context, $payload, $secret, \\Tmilos\\JoseJwt\\Jws\\JwsAlgorithm::RS256, $extraHeader);\n\n// RS384\n$privateKey = openssl_get_privatekey($filename);\n$token = \\Tmilos\\JoseJwt\\Jwt::encode($context, $payload, $secret, \\Tmilos\\JoseJwt\\Jws\\JwsAlgorithm::RS384, $extraHeader);\n\n// RS512\n$privateKey = openssl_get_privatekey($filename);\n$token = \\Tmilos\\JoseJwt\\Jwt::encode($context, $payload, $secret, \\Tmilos\\JoseJwt\\Jws\\JwsAlgorithm::RS512, $extraHeader);\n\n// decode\n$header = \\Tmilos\\JoseJwt\\Jwt::header($token);\n// eventually also use other header data to indicate which key should be used\nswitch($header['alg']) {\n    case \\Tmilos\\JoseJwt\\Jws\\JwsAlgorithm::NONE:\n        $key = null;\n        break;\n    case \\Tmilos\\JoseJwt\\Jws\\JwsAlgorithm::HS256:\n    case \\Tmilos\\JoseJwt\\Jws\\JwsAlgorithm::HS384:\n    case \\Tmilos\\JoseJwt\\Jws\\JwsAlgorithm::HS512:\n        $key = $secret;\n        break;\n    case \\Tmilos\\JoseJwt\\Jws\\JwsAlgorithm::RS256:\n    case \\Tmilos\\JoseJwt\\Jws\\JwsAlgorithm::RS384:\n    case \\Tmilos\\JoseJwt\\Jws\\JwsAlgorithm::RS512:\n        $key = $publicKey;\n        break;\n}\n$payload = \\Tmilos\\JoseJwt\\JWT::decode($context, $token, $key);\n```\n\n## JWE API\n\n```php\n$factory = new \\Tmilos\\JoseJwt\\Context\\DefaultContextFactory();\n$context = $factory-\u003eget();\n\n// Symmetric\n$payload = ['msg' =\u003e 'Hello!'];\n$extraHeader = ['iam'=\u003e'my-id'];\n\n// DIR - A128CBC-HS256\n$secret = '...'; // 256 bits secret\n$token = \\Tmilos\\JoseJwt\\Jwe::encode($context, $payload, $secret, \\Tmilos\\JoseJwt\\Jwe\\JweAlgorithm::DIR, \\Tmilos\\JoseJwt\\Jwe\\JweEncryption::A128CBC_HS256, $extraHeaders);\n\n// DIR - A192CBC-HS384\n$secret = '...'; // 384 bits secret\n$token = \\Tmilos\\JoseJwt\\Jwe::encode($context, $payload, $secret, \\Tmilos\\JoseJwt\\Jwe\\JweAlgorithm::DIR, \\Tmilos\\JoseJwt\\Jwe\\JweEncryption::A192CBC_HS384, $extraHeaders);\n\n// DIR - A256CBC-HS512\n$secret = '...'; // 512 bits secret\n$token = \\Tmilos\\JoseJwt\\Jwe::encode($context, $payload, $secret, \\Tmilos\\JoseJwt\\Jwe\\JweAlgorithm::DIR, \\Tmilos\\JoseJwt\\Jwe\\JweEncryption::A256CBC_HS512, $extraHeaders);\n\n// decode\n$payload = \\Tmilos\\JoseJwt\\Jwe::decode($context, $token, $secret);\n\n// RSA\n$myPrivateKey = openssl_get_privatekey();\n$partyPublicKey = openssl_get_publickey();\n\n// RSA_OAEP - A128CBC-HS256\n$token = \\Tmilos\\JoseJwt\\Jwe::encode($context, $payload, $partyPublicKey, \\Tmilos\\JoseJwt\\Jwe\\JweAlgorithm::RSA_OAEP, \\Tmilos\\JoseJwt\\Jwe\\JweEncryption::A128CBC_HS256, $extraHeaders);\n\n// RSA_OAEP - A256CBC-HS512\n$token = \\Tmilos\\JoseJwt\\Jwe::encode($context, $payload, $partyPublicKey, \\Tmilos\\JoseJwt\\Jwe\\JweAlgorithm::RSA_OAEP, \\Tmilos\\JoseJwt\\Jwe\\JweEncryption::A256CBC_HS512, $extraHeaders);\n\n// decode\n$payload = \\Tmilos\\JoseJwt\\Jwe::decode($context, $token, $myPrivateKey);\n\n// read header w/out decryption\n$header = \\Tmilos\\Tmilos\\JoseJwt\\Jwe::decode($token); // {\"alg\": \"A192KW\", \"enc\": \"A128CBC-HS256\", \"typ\": \"JWT\", \"custom\": \"X\"}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftmilos%2Fjose-jwt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftmilos%2Fjose-jwt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftmilos%2Fjose-jwt/lists"}