{"id":36427599,"url":"https://github.com/ampersa/json-signer","last_synced_at":"2026-01-11T18:06:07.736Z","repository":{"id":56947311,"uuid":"82168227","full_name":"ampersa/json-signer","owner":"ampersa","description":"Validate JSON strings with a signed hash","archived":false,"fork":false,"pushed_at":"2019-01-30T22:11:18.000Z","size":19,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-05-12T02:06:48.917Z","etag":null,"topics":["json","json-signer","signature","signer"],"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/ampersa.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":"2017-02-16T10:21:19.000Z","updated_at":"2019-01-30T22:10:43.000Z","dependencies_parsed_at":"2022-08-21T07:50:11.464Z","dependency_job_id":null,"html_url":"https://github.com/ampersa/json-signer","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/ampersa/json-signer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ampersa%2Fjson-signer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ampersa%2Fjson-signer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ampersa%2Fjson-signer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ampersa%2Fjson-signer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ampersa","download_url":"https://codeload.github.com/ampersa/json-signer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ampersa%2Fjson-signer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28317547,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-11T14:58:17.114Z","status":"ssl_error","status_checked_at":"2026-01-11T14:55:53.580Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["json","json-signer","signature","signer"],"created_at":"2026-01-11T18:06:06.775Z","updated_at":"2026-01-11T18:06:07.731Z","avatar_url":"https://github.com/ampersa.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JSON Signer and Validator\nSigns JSON strings with a signed hash and validates signed strings.\n\n*Version 1.3*\n\n## Installation\nInstallation is via composer:\n```\ncomposer require ampersa/json-signer\n```\n\n## Usage\nTo sign a JSON string, pass the signing key to the new Signer and call sign() passing the JSON string:\n```php\n$signer = new \\Ampersa\\JsonSigner\\Signer('SIGNINGKEY');\n$signed = $signer-\u003esign('{\"key1\":\"value1\",\"array1\":{\"key2\":\"value2\",\"key3\":\"value3\"}}');\n\n// Returns: {\"key1\":\"value1\",\"array1\":{\"key2\":\"value2\",\"key3\":\"value3\"},\"__s\":\"6bf4dbb38474dfbffa5980cae38d0e24fe73100e710f6a97efc8fb3620655ab0\"}\n```\n\nAlternatively, to return the signature and leave the JSON string intact, call signature() with the JSON string:\n```php\n$signer = new \\Ampersa\\JsonSigner\\Signer('SIGNINGKEY');\n$signed = $signer-\u003esignature('{\"key1\":\"value1\",\"array1\":{\"key2\":\"value2\",\"key3\":\"value3\"}}');\n\n// Returns: 6bf4dbb38474dfbffa5980cae38d0e24fe73100e710f6a97efc8fb3620655ab0\n```\n\nTo validate a signed JSON string, call verify() passing the signed JSON string:\n```php\n$signer = new \\Ampersa\\JsonSigner\\Signer('SIGNINGKEY');\n$signed = $signer-\u003everify('{\"key1\":\"value1\",\"array1\":{\"key2\":\"value2\",\"key3\":\"value3\"},\"__s\":\"6bf4dbb38474dfbffa5980cae38d0e24fe73100e710f6a97efc8fb3620655ab0\"}');\n\n// Returns: true\n```\n\nValidating a signature separately is as simple as passing the signature as the second argument to verify():\n```php\n$signer = new \\Ampersa\\JsonSigner\\Signer('SIGNINGKEY');\n$signed = $signer-\u003everify('{\"key1\":\"value1\",\"array1\":{\"key2\":\"value2\",\"key3\":\"value3\"}}', '6bf4dbb38474dfbffa5980cae38d0e24fe73100e710f6a97efc8fb3620655ab0');\n\n// Returns: true\n```\n\n## Signers\n2 Signer classes are included:\n* AppendSigner\n* PackageSigner\n\nThe Signer defaults to AppendSigner, appending the signature key to the JSON object.\n\nPackageSigner packages the original JSON object and signature key into a new parent object, i.e:\n```php\n$signer = (new \\Ampersa\\JsonSigner\\Signer('SIGNINGKEY'))\n            -\u003esetSigner(new \\Ampersa\\JsonSigner\\Signers\\PackageSigner);\n$signed = $signer-\u003esign('{\"key1\":\"value1\",\"array1\":{\"key2\":\"value2\",\"key3\":\"value3\"}}');\n\n// Returns: {\"__orig\":{\"key1\":\"value1\",\"array1\":{\"key2\":\"value2\",\"key3\":\"value3\"}},\"__s\":\"6bf4dbb38474dfbffa5980cae38d0e24fe73100e710f6a97efc8fb3620655ab0\"}\n\n$signer = (new \\Ampersa\\JsonSigner\\Signer('SIGNINGKEY'))\n            -\u003esetSigner(new \\Ampersa\\JsonSigner\\Signers\\PackageSigner);\n$signed = $signer-\u003everify('{\"__orig\":{\"key1\":\"value1\",\"array1\":{\"key2\":\"value2\",\"key3\":\"value3\"}},\"__s\":\"6bf4dbb38474dfbffa5980cae38d0e24fe73100e710f6a97efc8fb3620655ab0\"}');\n\n// Returns: true\n```\n\n**Be sure to use the correct Signer class for both signing and verifying**\n\nSigner classes may also be accessed directly:\n```php\n$signer = new \\Ampersa\\JsonSigner\\Signers\\PackageSigner('SIGNINGKEY');\n$signed = $signer-\u003esign('{\"key1\":\"value1\",\"array1\":{\"key2\":\"value2\",\"key3\":\"value3\"}}');\n\n// Returns: {\"__orig\":{\"key1\":\"value1\",\"array1\":{\"key2\":\"value2\",\"key3\":\"value3\"}},\"__s\":\"6bf4dbb38474dfbffa5980cae38d0e24fe73100e710f6a97efc8fb3620655ab0\"}\n```\n\n## Config\n\n###Signature Key\nSet the key used to hold to signature in the signed string. This can be used to avoid collisions with existing keys.\n\n**If sign() is called on a string which already contains the signature key, an Exception will be thrown**\n```php\n$signer = new \\Ampersa\\JsonSigner\\Signer('SIGNINGKEY');\n$signer-\u003esetSignatureKey('customSignature');\n$signed = $signer-\u003esign('{\"key1\":\"value1\",\"array1\":{\"key2\":\"value2\",\"key3\":\"value3\"}}');\n\n// Returns: {\"key1\":\"value1\",\"array1\":{\"key2\":\"value2\",\"key3\":\"value3\"},\"customSignature\":\"6bf4dbb38474dfbffa5980cae38d0e24fe73100e710f6a97efc8fb3620655ab0\"}\n```\n\n###Hash Algorithm\nThe signer defaults to using SHA256 as the signing algorithm. This can be changed, either via the second construct argument, or via setAlgorithm():\n```php\n$signer = new \\Ampersa\\JsonSigner\\Signer('SIGNINGKEY', 'md5');\n$signed = $signer-\u003esign('{\"key1\":\"value1\",\"array1\":{\"key2\":\"value2\",\"key3\":\"value3\"}}');\n\n// Returns: {\"key1\":\"value1\",\"array1\":{\"key2\":\"value2\",\"key3\":\"value3\"},\"__s\":\"2eedf7bd7c18ae0e8db2f6dc86f5df57\"}\n\n$signer = new \\Ampersa\\JsonSigner\\Signer('SIGNINGKEY');\n$signer-\u003esetAlgorithm('sha1');\n$signed = $signer-\u003esign('{\"key1\":\"value1\",\"array1\":{\"key2\":\"value2\",\"key3\":\"value3\"}}');\n\n// Returns: {\"key1\":\"value1\",\"array1\":{\"key2\":\"value2\",\"key3\":\"value3\"},\"__s\":\"e8d409703677aef50b897fa0e0cb7fc6898ae690\"}\n```\n\n###Package Key\nWhen utilising the PackageSigner class, you may set the key used to hold to original JSON package in the signed string:\n\n```php\n$signer = new \\Ampersa\\JsonSigner\\Signers\\PackageSigner('SIGNINGKEY');\n$signer-\u003esetPackageKey('package');\n$signed = $signer-\u003esign('{\"key1\":\"value1\",\"array1\":{\"key2\":\"value2\",\"key3\":\"value3\"}}');\n\n// Returns: {\"package\": {\"key1\":\"value1\",\"array1\":{\"key2\":\"value2\",\"key3\":\"value3\"}},\"customSignature\":\"6bf4dbb38474dfbffa5980cae38d0e24fe73100e710f6a97efc8fb3620655ab0\"}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fampersa%2Fjson-signer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fampersa%2Fjson-signer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fampersa%2Fjson-signer/lists"}