{"id":22579788,"url":"https://github.com/taluu/json-encoder-exercise","last_synced_at":"2025-03-28T16:23:08.712Z","repository":{"id":265763836,"uuid":"861696338","full_name":"Taluu/json-encoder-exercise","owner":"Taluu","description":"A bit of tinkering with encoding / decoding json values over http","archived":false,"fork":false,"pushed_at":"2024-09-27T14:32:29.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-25T05:15:31.173Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Taluu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-09-23T11:12:18.000Z","updated_at":"2024-09-27T14:32:32.000Z","dependencies_parsed_at":"2024-11-30T21:04:04.563Z","dependency_job_id":"7dd253d1-8034-4c7e-a363-fe91c55abb04","html_url":"https://github.com/Taluu/json-encoder-exercise","commit_stats":null,"previous_names":["taluu/json-encoder-exercise"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Taluu%2Fjson-encoder-exercise","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Taluu%2Fjson-encoder-exercise/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Taluu%2Fjson-encoder-exercise/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Taluu%2Fjson-encoder-exercise/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Taluu","download_url":"https://codeload.github.com/Taluu/json-encoder-exercise/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246059824,"owners_count":20717158,"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":[],"created_at":"2024-12-08T05:12:22.130Z","updated_at":"2025-03-28T16:23:08.690Z","avatar_url":"https://github.com/Taluu.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"JSON encoder / Decoder exercice\n===============================\n\nThis is a simple exercise, the goal being to be able to encrypt some values on a\nJSON body (only on a first level), or decrypt values in it, sign a JSON body or \ncheck if a provided signature matches the signature used in the program.\n\nHow to build\n------------\n### From Source\n\n```bash\ngit clone https://github.com/Taluu/json-encoder-exercise\ncd json-encrypter-exercise\ngo build -o bin/json-encrypter-exercise\nbin/json-encrypter-exercise -key \"my secret key\"\n```\n\nThe `-key` flag is important here, to set the key used to generate and verify\nsignatures for the `/sign` and `/verify` endpoints. \n\nOther available flags are `-domain` and `-port`, with respective default values\nbeing `localhost` and `8080`.\n\n### From binary release\nBinaries should be released on the Releases page on the github repo.\n\nEndpoints\n---------\nNote : all example are hitting as if the domain is `localhost` and the port\n`8080`, and the key `test`.\n\nFor security concerns, the key should of course not be plaintext when launching\nthe binary, but for the sake of simplicity and this being out of scope for this\nexercice, let's pass this as plaintext.\n\n`bin/json-encoder-exercise -domain localhost -port 8080 -key test`\n\n### Encrypting data\nYou can encrypt data by hitting the endpoint `/encrypt` on a POST request, with\na valid json object :\n\n```bash\ncurl http://localhost:8080/encrypt -X POST -d \"{\\\"foo\\\": \\\"bar\\\", \\\"number\\\": 1, \\\"object\\\": {\\\"one\\\": \\\"two\\\", \\\"three\\\": 3}}\"\n```\n\nYou should get a 200 response with the following values :\n\n```json\n{\n    \"foo\": \"YmFy\",\n    \"number\":\"MQ==\",\n    \"object\":\"eyJvbmUiOiJ0d28iLCJ0aHJlZSI6M30=\"\n}\n```\n\nOn errors, you can have a 405 on a method other than POST, or 400 if the json\nbody cannot be decoded into an object.\n\n### Decrypting data\nYou can decrypt data, and the server will try to decode also nested values (such\nas in an object or an array) by hitting the endpoint `/decrypt` on a POST request,\nwith a valid json object :\n\n```bash\ncurl http://localhost:8080/decrypt -X POST -d \"{\\\"foo\\\": \\\"YmFy\\\", \\\"number\\\": 1, \\\"object\\\": \\\"eyJvbmUiOiJ0d28iLCJ0aHJlZSI6M30=\\\"}\"\n```\n\nYou should then get a 200 response with the following values :\n\n```json\n{\n    \"foo\": \"bar\",\n    \"number\": 1,\n    \"object\": {\n        \"one\": \"two\",\n        \"three\": 3\n    }\n}\n```\n\nIf an encoded value was a json object or array, it will be returned as such, but\nif there was an encrypted value in them, they won't be decrypted.\n\nOn errors, you can have a 405 on a method other than POST, or 400 on bad json\ninput.\n\n### Signing data\nYou can sign data (any data) as long as it's in a json format, by hitting the\nendpoint `/sign` like the following :\n\n```bash\ncurl http://localhost:8080/sign -X POST -d \"{\\\"foo\\\": \\\"YmFy\\\"}\"\n```\n\nYou should get a 200 response with the following json body :\n\n```json\n{\n    \"signature\": \"384854f7b73ed17f1107006aa49e3813a7d1f9f3ce75fa0b770bc00e35c8ea82\",\n    \"data\": {\n        \"foo\":\"YmFy\"\n    }\n}\n```\n\nThe `data` property of the returned objet will be of the type of the given data\n(if it's a scalar, it will be scalar, an array an array, ... and so on)\n\nOn errors, you can have a 405 for a method other than POST, or 400 on bad json\ninput (or empty input).\n\n## Verifying data\nAs data can be signed with the `/sign` endpoint, signed data can also be\nverified against a signature with the `/verify` endpoint on a POST request,\nlike the following :\n\n```bash\ncurl http://localhost:8080/verify -X POST -d \"{\\\"signature\\\":\\\"51fb0f2895400032daf856082634c635f5fe21a2848b4b2337ebeb3fc0e9c05c\\\",\\\"data\\\":{\\\"foo\\\":\\\"bar\\\"}}\"\n```\n\nThe expected body should be as the response of the sign body :\n\n```json\n{\n    \"data\": { ... },\n    \"signature\": \"...\"\n}\n```\n\nThe data can be anything as long as it's a json valid body.\n\nIf the signature is valid, an empty response with a 204 http code will be\nreturned, other a 400 will be returned if it's invalid. A 405 will be returned\nif it's not a POST request.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftaluu%2Fjson-encoder-exercise","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftaluu%2Fjson-encoder-exercise","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftaluu%2Fjson-encoder-exercise/lists"}