{"id":21202413,"url":"https://github.com/jarrydk/jwt-tool","last_synced_at":"2025-07-29T07:12:52.013Z","repository":{"id":168585826,"uuid":"644327795","full_name":"jarryDk/jwt-tool","owner":"jarryDk","description":"JWT Tool - PrettyPrint and generate tokens","archived":false,"fork":false,"pushed_at":"2025-02-20T11:53:21.000Z","size":39,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-14T22:31:03.345Z","etag":null,"topics":["authorization","java","jwt","jwt-token"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jarryDk.png","metadata":{"files":{"readme":"README.adoc","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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-23T09:39:28.000Z","updated_at":"2025-02-20T11:53:25.000Z","dependencies_parsed_at":null,"dependency_job_id":"a86964e1-2c0c-4d5d-b51a-6b232317a970","html_url":"https://github.com/jarryDk/jwt-tool","commit_stats":null,"previous_names":["jarrydk/jwt-tool"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/jarryDk/jwt-tool","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jarryDk%2Fjwt-tool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jarryDk%2Fjwt-tool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jarryDk%2Fjwt-tool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jarryDk%2Fjwt-tool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jarryDk","download_url":"https://codeload.github.com/jarryDk/jwt-tool/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jarryDk%2Fjwt-tool/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267645024,"owners_count":24120874,"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","status":"online","status_checked_at":"2025-07-29T02:00:12.549Z","response_time":2574,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["authorization","java","jwt","jwt-token"],"created_at":"2024-11-20T20:15:50.832Z","updated_at":"2025-07-29T07:12:51.975Z","avatar_url":"https://github.com/jarryDk.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"= Jwt Tool\n\nThis project is all aboute JSON Web Token. \n\nWe get the option to convert a `JWT` to plaintext or json - basicly get the token in a human readable format.\n\nWe also get the option to generate `JWT` with a validit signature.\n\n== Use\n\n----\nUsage: jwt-tool [-hV] [-f=\u003cformat\u003e] [-k=\u003ckid\u003e] [-p=\u003cpayload\u003e] [-t=\u003ctoken\u003e]\n  -f, --format=\u003cformat\u003e     Output format json or plantext (default)\n  -h, --help                Show this help message and exit.\n  -k, --kid=\u003ckid\u003e           Input will be kid in header\n  -p, --payload=\u003cpayload\u003e   Input will have to be base64 encoded Json!\n  -t, --token=\u003ctoken\u003e       Input will have to be a JWT!\n  -V, --version             Print version information and exit.\n----\n\n== Sample\n\nTIP: You might like to have `jq` installed - but you most likely already have. `sudo dnf install jq -y`\n\n=== PrettyPrint token\n\n.Input nativ - PrettyPrint token (output in plaintext format)\n[source,bash]\n----\ntarget/jwt-tool-1.0.0-SNAPSHOT-runner \\\n    -t eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MTIzNDU2Nzg5LCJuYW1lIjoiSm9zZXBoIn0.OpOSSw7e485LOP5PrzScxHb7SR6sAOMRckfFwi4rp7o\n----\n\n.Output nativ - PrettyPrint token (output in plaintext format)\n----\nToken ::\neyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MTIzNDU2Nzg5LCJuYW1lIjoiSm9zZXBoIn0.OpOSSw7e485LOP5PrzScxHb7SR6sAOMRckfFwi4rp7o\nHeader ::\n{\n    \"alg\": \"HS256\",\n    \"typ\": \"JWT\"\n}\nPayload ::\n{\n    \"id\": 123456789,\n    \"name\": \"Joseph\"\n}\n----\n\n=== Generate token\n\n.Input nativ  - Generate token (output in plaintext format)\n[source,bash]\n----\ntarget/jwt-tool-1.0.0-SNAPSHOT-runner \\\n    -p $(echo \"{\\\"id\\\":42,\\\"name\\\":\\\"Duke\\\"}\" | base64)\n----\n\n.Output nativ - Generate token (output in plaintext format)\n----\nToken ::\neyJraWQiOiIiLCJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpZCI6NDIsIm5hbWUiOiJEdWtlIiwiZXhwIjoxNjg0ODMwNjQ1LCJpYXQiOjE2ODQ4MzAzNDUsImp0aSI6ImJhMzlhM2ZiLWE3ZjEtNDA2Yi1hMTZmLTUzZTMyMmU2MGE1NiJ9.b9SKNynAKWbzAhiWGHoSXwlzsXC-FQAj8OPMVplgL1wMDbAPARbz0d1_etmQNsoVk8X1s5wgRt_aqXVIva3bFzWbxJ52nlkbOHfqQQXC43hK9nAY7pPilnXCeXUh7daQiaLm6wsUEijJ6mN5ZuN1yUfqosd8U8dbZGAupqKkNArJ9m4Di2aMAcVQOEI7XJ3et7EMaqHWEQ3R-uZxEIrmkIw8szhFFgF7HifTuP0dcIC8inQ2HB1sbRLfINOSjc9MemaIkOQxESPrLKHwoZTGjpIj-FLMwqtyr8Mbm5B9gMLCAeZl6D_VqK7sTelH4y_r0llvOTst7iQTGuDRfReQ8Q\nHeader ::\n{\n    \"typ\": \"JWT\",\n    \"alg\": \"RS256\"\n}\nPayload ::\n{\n    \"id\": 42,\n    \"name\": \"Duke\",\n    \"exp\": 1684830645,\n    \"iat\": 1684830345,\n    \"jti\": \"ba39a3fb-a7f1-406b-a16f-53e322e60a56\"\n}\n----\n\n.Input nativ  - Generate token (output in json format)\n[source,bash]\n----\ntarget/jwt-tool-1.0.0-SNAPSHOT-runner \\\n    -p $(echo \"{\\\"id\\\":42,\\\"name\\\":\\\"Duke\\\"}\" | base64) \\\n    -f json | jq\n----\n\n.Output nativ - Generate token (output in plaintext format)\n[source,json]\n----\n{\n    \"token\": \"eyJraWQiOiIiLCJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpZCI6NDIsIm5hbWUiOiJEdWtlIiwiZXhwIjoxNjg0ODMyMjU3LCJpYXQiOjE2ODQ4MzE5NTcsImp0aSI6IjEzZDQwZTVmLTU0NWEtNGRlNy1iZDM3LTM2ZDM1YjBjMmFkYyJ9.Adx-Tr93UEm-S9MsSwgIWH6v0x0fg3dluv13DxL7129kEI0y_CAGvVBIW4-SdK6flBA68_ncbkWDndjYxtnOB0aOGhLwvoA6HTJBwKRB2Qqxs1cdDXMtOOCexM9CPWmMAy_j3Y6GeAURVB3bhVuC9WNMwDM7bjH46K2b637nhCXrRDQH3AgXE-apwgl1fgKe1yMzogwBKm60v4jpbcn_u-C_BXG_DgGoyoOa9RL7EOlWffcYA8d2O5hEHYteK2zWHek1iucUogidjKohuEdudyBxySOupBukwLuPAzlTXoAEN5Y4QWC2gE7AKiJnKUJga4kDmstp4wY5X4mVIn5ltQ\",\n    \"header\": {\n        \"kid\": \"\",\n        \"typ\": \"JWT\",\n        \"alg\": \"RS256\"\n    },\n    \"payload\": {\n        \"id\": 42,\n        \"name\": \"Duke\",\n        \"exp\": 1684832257,\n        \"iat\": 1684831957,\n        \"jti\": \"13d40e5f-545a-4de7-bd37-36d35b0c2adc\"\n    }\n}\n----\n\n.Input nativ  - Generate token (output in json format) and use jq to get only the token\n[source,bash]\n----\ntarget/jwt-tool-1.0.0-SNAPSHOT-runner \\\n    -p $(echo \"{\\\"id\\\":42,\\\"name\\\":\\\"Duke\\\"}\" | base64) \\\n    -f json | jq --raw-output '.token'\n----\n\n== Change location of privateKey.pem and `publicKey.pem\n\nHow to use `privateKey.pem` and `publicKey.pem` located outside this project.\n\nWell we need to change the value of `smallrye.jwt.sign.key.location` and `smallrye.jwt.encrypt.key.location` in the \nfile `application.properties`. The change/configuration can be done in many ways - her is a way to to it using `System properties` and `Environment variables`.\n\n.Use System properties\n[source,bash]\n----\njwt-tool \\\n    -p $(echo \"{\\\"id\\\":42,\\\"name\\\":\\\"Duke\\\"}\" | base64) \\\n    -Dsmallrye.jwt.sign.key.location=$HOME/keys/privateKey.pem \\\n    -Dsmallrye.jwt.encrypt.key.location=$HOME/keys/publicKey.pem\n----\n\n.Use Environment variables\n[source,bash]\n----\nexport SMALLRYE_JWT_SIGN_KEY_LOCATION=$HOME/keys/privateKey.pem\nexport SMALLRYE_JWT_ENCRYPT_KEY_LOCATION=$HOME/keys/publicKey.pem\njwt-tool \\\n    -p $(echo \"{\\\"id\\\":42,\\\"name\\\":\\\"Duke\\\"}\" | base64)\n----\n\n\n== Build\n\n.Build Nativ\n[source,bash]\n----\nmvn clean package -Pnative\n----\n\nTIP: You might like to have `GRAALVM_HOME` as an Environment variables before building native and you might like to execute `gu install native-image` in the folder `$GRAALVM_HOME/bin` too.\n\n.Build JVM\n[source,bash]\n----\nmvn clean package\n----\n\n.Build Uber jar\n[source,bash]\n----\nmvn clean package -Dquarkus.package.type=uber-jar\n----\n\n== Use in different modes\n\n=== Native Mode\n\n.Run nativ - PrettyPrint token (output in plaintext format)\n[source,bash]\n----\ntarget/jwt-tool-1.0.0-SNAPSHOT-runner \\\n    -t eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MTIzNDU2Nzg5LCJuYW1lIjoiSm9zZXBoIn0.OpOSSw7e485LOP5PrzScxHb7SR6sAOMRckfFwi4rp7o\n----\n\n.Run nativ - PrettyPrint token (output in json format)\n[source,bash]\n----\npackage -Pnative\ntarget/jwt-tool-1.0.0-SNAPSHOT-runner \\\n    -t eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MTIzNDU2Nzg5LCJuYW1lIjoiSm9zZXBoIn0.OpOSSw7e485LOP5PrzScxHb7SR6sAOMRckfFwi4rp7o \\\n    -f json | jq\n----\n\n.Run nativ  - Generate token (output in plaintext format)\n[source,bash]\n----\npackage -Pnative\ntarget/jwt-tool-1.0.0-SNAPSHOT-runner \\\n    -k ucJxucWD1VfqR5NzBkJfx6FsYbbGxG18y9mVkk1XabY \\\n    -p $(echo \"{\\\"id\\\":42,\\\"name\\\":\\\"Duke\\\"}\" | base64)\n----\n\n.Run nativ  - Generate token (output in json format)\n[source,bash]\n----\npackage -Pnative\ntarget/jwt-tool-1.0.0-SNAPSHOT-runner \\\n    -k ucJxucWD1VfqR5NzBkJfx6FsYbbGxG18y9mVkk1XabY \\\n    -p $(echo \"{\\\"id\\\":42,\\\"name\\\":\\\"Duke\\\"}\" | base64) \\\n    -f json | jq\n----\n\n=== JVM Mode\n\n.Run via JVM - PrettyPrint token\n[source,bash]\n----\nmvn clean package\njava -jar target/quarkus-app/quarkus-run.jar \\\n    -t eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MTIzNDU2Nzg5LCJuYW1lIjoiSm9zZXBoIn0.OpOSSw7e485LOP5PrzScxHb7SR6sAOMRckfFwi4rp7o\n----\n\n.Run via JVM - Generate token\n[source,bash]\n----\nmvn clean package\njava -jar target/quarkus-app/quarkus-run.jar \\\n    -k ucJxucWD1VfqR5NzBkJfx6FsYbbGxG18y9mVkk1XabY \\\n    -p $(echo \"{\\\"id\\\":42,\\\"name\\\":\\\"Duke\\\"}\" | base64)\n----\n\n=== JVM (Uber-Jars) Mode\n\n.Run via JVM (Uber-Jars)\n[source,bash]\n----\nmvn clean package\njava -jar target/jwt-tool-1.0.0-SNAPSHOT-runner.jar \\\n    -t eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MTIzNDU2Nzg5LCJuYW1lIjoiSm9zZXBoIn0.OpOSSw7e485LOP5PrzScxHb7SR6sAOMRckfFwi4rp7o\n----\n\n\n=== DEV Mode\n\n.Run in dev mode - PrettyPrint token\n[source,bash]\n----\nmvn quarkus:dev \\\n    -Dquarkus.args=\"-t eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MTIzNDU2Nzg5LCJuYW1lIjoiSm9zZXBoIn0.OpOSSw7e485LOP5PrzScxHb7SR6sAOMRckfFwi4rp7o\"\n----\n\n.Run in dev mode - PrettyPrint token (json output)\n[source,bash]\n----\nmvn quarkus:dev \\\n    -Dquarkus.args=\"-t eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MTIzNDU2Nzg5LCJuYW1lIjoiSm9zZXBoIn0.OpOSSw7e485LOP5PrzScxHb7SR6sAOMRckfFwi4rp7o -f json\"\n----\n\n\n.Run in dev mode - Generate token\n[source,bash]\n----\nmvn quarkus:dev \\\n    -Dquarkus.args=\"-k ucJxucWD1VfqR5NzBkJfx6FsYbbGxG18y9mVkk1XabY -p $(echo \"{\\\"id\\\":42,\\\"name\\\":\\\"Duke\\\"}\" | base64)\"\n----\n\n.Run in dev mode - Generate token (json output)\n[source,bash]\n----\nmvn quarkus:dev \\\n    -Dquarkus.args=\"-k ucJxucWD1VfqR5NzBkJfx6FsYbbGxG18y9mVkk1XabY -p $(echo \"{\\\"id\\\":42,\\\"name\\\":\\\"Duke\\\"}\" | base64) -f json\"\n----\n\n== Project structure\n\n.Get the Project structure\n[source,bash]\n----\ntree -I target\n----\n\n.Output of tree\n----\n.\n├── pom.xml\n├── README.adoc\n├── src\n│   ├── main\n│   │   ├── java\n│   │   │   └── dk\n│   │   │       └── jarry\n│   │   │           └── picocli\n│   │   │               ├── JwtTokenCommand.java\n│   │   │               └── JwtTokenService.java\n│   │   └── resources\n│   │       ├── application.properties\n│   │       ├── privateKey.pem\n│   │       ├── publicKey.pem\n│   │       └── rsaPrivateKey.pem\n│   └── test\n│       └── java\n│           └── dk\n│               └── jarry\n│                   └── picocli\n│                       └── JwtTokenServiceTest.java\n└── todo-service-hack.json\n----\n\nWe have a simple project strukture where `application.properties` tells the location of `privateKey.pem` and `publicKey.pem`.\n\n== Make Keycloak use a keys generated outside Keycloak\n\n.Generate Keys\n[source,bash]\n----\nopenssl genrsa -out rsaPrivateKey.pem 2048\nopenssl pkcs8 -topk8 -nocrypt -inform pem -in rsaPrivateKey.pem -outform pem -out privateKey.pem\nopenssl rsa -pubout -in rsaPrivateKey.pem -out publicKey.pem\n----\n\nTIP: I executed the above command in the folder `jwt-tool/src/main/resource`\n\n== Get a JWT from Keycloak\n\n.Grant type set to password\n[source,bash]\n----\ncurl -X POST https://keycloak.jarry.dk:8543/realms/jarry/protocol/openid-connect/token \\\n    --user todo-service-hack:todo-service-hack-secret \\\n    -H 'content-type: application/x-www-form-urlencoded' \\\n    -d 'username=micbn\u0026password=change_me\u0026grant_type=password' | jq --raw-output '.access_token'\n----\n\n== Install\n\n[source,bash]\n----\nsudo install -m 555 target/jwt-tool-0.0.1-runner /usr/local/bin/jwt-tool\n----\n\n== Guides\n\n- https://quarkus.io/guides/picocli\n- https://quarkus.io/guides/security-jwt\n- https://quarkus.io/guides/security-jwt-build\n- https://quarkus.io/guides/config\n- https://quarkus.io/guides/config-reference#configuration-sources\n\n== ANSI_escape_code\n\nhttps://en.wikipedia.org/wiki/ANSI_escape_code#3-bit_and_4-bit","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjarrydk%2Fjwt-tool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjarrydk%2Fjwt-tool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjarrydk%2Fjwt-tool/lists"}