{"id":19300029,"url":"https://github.com/zfegg/http-content-crypt","last_synced_at":"2025-02-24T01:23:54.977Z","repository":{"id":57090474,"uuid":"80807559","full_name":"zfegg/http-content-crypt","owner":"zfegg","description":"RsaAes HTTP Content crypt for psr7 middleware","archived":false,"fork":false,"pushed_at":"2017-10-31T06:07:55.000Z","size":24,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-05T22:42:06.313Z","etag":null,"topics":["crypt","signature"],"latest_commit_sha":null,"homepage":null,"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/zfegg.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-03T07:37:41.000Z","updated_at":"2017-02-03T07:49:50.000Z","dependencies_parsed_at":"2022-08-20T15:30:17.481Z","dependency_job_id":null,"html_url":"https://github.com/zfegg/http-content-crypt","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/zfegg%2Fhttp-content-crypt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zfegg%2Fhttp-content-crypt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zfegg%2Fhttp-content-crypt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zfegg%2Fhttp-content-crypt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zfegg","download_url":"https://codeload.github.com/zfegg/http-content-crypt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240401362,"owners_count":19795535,"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":["crypt","signature"],"created_at":"2024-11-09T23:13:27.539Z","updated_at":"2025-02-24T01:23:54.953Z","avatar_url":"https://github.com/zfegg.png","language":"PHP","readme":"Http Content Signature/Crypt\n============================\n\nHTTP content crypt/signature for PSR7 middleware\n\nInstallation\n------------\n\nInstall via composer:\n\n~~~bash\n# composer require zfegg/http-content-crypt\n~~~\n\nUsage\n-----\n\n### ContentCryptMiddleware\n\nContent crypt using RSA+AES.\n\n#### HTTP stream:\n\n~~~\nPOST /action HTTP/1.1\nHost: localhost\nContent-Type: application/json\nAccept: application/json\nX-Content-Encoding: rsaaes, base64\nX-Crypto-Key: keyid=1; data=`Urlencode(BASE64.encode(RSA.encode(AesKey)))`\n\n`BASE64.encode(AES.encode('{\"test\":\"test content\"}'));`\n\nHTTP/1.1 200 OK\nContent-Type: application/json\nContent-Length: n\nX-Content-Encoding: rsaaes, base64\n\n`BASE64.decode(AES.decode('{\"test\":\"test response content\"}'));`\n~~~\n\n#### Slim example:\n\n~~~php\n\nuse Psr\\Http\\Message\\ServerRequestInterface;\n\n$app = new \\Slim\\App($settings);\n\n$container = $app-\u003egetContainer();\n$container[ContentCryptMiddleware::class] = function () {\n    $middleware = new ContentCryptMiddleware();\n\n    $rsa = Rsa::factory([\n        'public_key' =\u003e '',\n        'private_key' =\u003e '',\n        'binary_output' =\u003e false,\n    ]);\n\n    $middleware-\u003esetFetchRsaCallback(function ($keyId, ServerRequestInterface $request) use ($rsa) {\n        return $rsa;\n    });\n    return $middleware;\n};\n\n$app-\u003epost('/test', function (\\Psr\\Http\\Message\\ServerRequestInterface $request, \\Slim\\Http\\Response $response) {\n    $rawBody = $request-\u003egetBody();\n    return $request-\u003ewrite($rawBody);\n})-\u003eadd(ContentCryptMiddleware::class);\n\n$app-\u003erun();\n~~~\n\n\n### ContentSignatureMiddleware\n\nContent signature verification using hash HMAC.\n\n\n在`POST`, `PUT`, `PATCH` 请求中, 对HTTP内容进行 HMAC-HASH 方式签名计算.\n\n内容签名主要是用于校验传输内容的合法性, 避免接口泄漏, 被恶意使用.\n\n#### HTTP stream:\n\n~~~\nPOST /action HTTP/1.1\nHost: localhost\nContent-Type: application/json\nAccept: application/json\nContent-Signature: keyid=1; value=(hash_hex); alg=(md5|sha1|...);\n\npayload\n\nHTTP/1.1 200 OK\nContent-Type: application/json\nContent-Length: n\nContent-Signature: keyid=1; value=(hash_hex); alg=(md5|sha1|...);\n\npayload\n~~~\n\n#### Slim example:\n\n~~~php\nuse Psr\\Http\\Message\\ServerRequestInterface;\n\n$app = new \\Slim\\App($settings);\n\n$container = $app-\u003egetContainer();\n$container[ContentSignatureMiddleware::class] = function () {\n    $middleware = new ContentSignatureMiddleware();\n    $middleware-\u003esetFetchRsaCallback(function ($keyId, ServerRequestInterface $request) {\n        return \"123456\";\n    });\n    return $middleware;\n};\n\n$app-\u003epost('/test', function (ServerRequestInterface $request, $response) {\n    $rawBody = $request-\u003egetBody();\n    return $request-\u003ewrite($rawBody);\n})-\u003eadd(ContentSignatureMiddleware::class);\n\n$app-\u003erun();\n~~~\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzfegg%2Fhttp-content-crypt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzfegg%2Fhttp-content-crypt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzfegg%2Fhttp-content-crypt/lists"}