{"id":21874521,"url":"https://github.com/smoren/url-security-manager-php","last_synced_at":"2025-04-15T01:24:17.028Z","repository":{"id":57053997,"uuid":"294719300","full_name":"Smoren/url-security-manager-php","owner":"Smoren","description":"Class for building, parsing, signing, signature checking, encrypting and decrypting URLs","archived":false,"fork":false,"pushed_at":"2021-04-07T14:15:54.000Z","size":28,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-28T13:21:16.204Z","etag":null,"topics":["encryption","security","url-builder","url-parser"],"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/Smoren.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":"2020-09-11T14:36:32.000Z","updated_at":"2024-07-15T12:00:10.000Z","dependencies_parsed_at":"2022-08-24T04:11:41.576Z","dependency_job_id":null,"html_url":"https://github.com/Smoren/url-security-manager-php","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Smoren%2Furl-security-manager-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Smoren%2Furl-security-manager-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Smoren%2Furl-security-manager-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Smoren%2Furl-security-manager-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Smoren","download_url":"https://codeload.github.com/Smoren/url-security-manager-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248986930,"owners_count":21194145,"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":["encryption","security","url-builder","url-parser"],"created_at":"2024-11-28T07:12:35.878Z","updated_at":"2025-04-15T01:24:17.012Z","avatar_url":"https://github.com/Smoren.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# url-security-manager\nClass for building, parsing, signing, signature checking, encrypting and decrypting URLs.\n\n### Install to your project\n```shell script\ncomposer require smoren/url-security-manager\n``` \n\n### Unit testing\n```shell script\ncomposer install\n./vendor/bin/codecept build\n./vendor/bin/codecept run unit tests/unit\n```\n\n### Demo\n##### Signing\n```php\nuse Smoren\\UrlSecurityManager\\UrlSecurityManager;\n\n$inputUrl = 'http://localhost:8080/test/path?p1=1\u0026p2=2\u0026p3=3\u0026p4=4';\n$secretKey = 'fvd76df89g7fdg89';\n\n// Let's sign some url with our secret key to send signed request to receiver\n$usmSender = UrlSecurityManager::parse($inputUrl)\n    // signature will be stored as value of query param \"sign\"\n    // only query params from array (2nd argument) will be signed\n    -\u003esetSignParams('sign', ['p1', 'p2', 'p3'])\n    -\u003esetSecretKey($secretKey) // giving secret key for signing\n    -\u003esign(); // create signature\n\n$signedUrl = $usmSender-\u003estringify();\necho $signedUrl;\n// http://localhost:8080/test/path?p1=1\u0026p2=2\u0026p3=3\u0026p4=4\u0026sign=5342af44ed716002a81a2872734729f5\n\n// Now we will try to check the signature of URL:\n$usmReceiver = UrlSecurityManager::parse($signedUrl)\n    -\u003esetSignParams('sign', ['p1', 'p2', 'p3'])\n    -\u003esetSecretKey($secretKey);\n$usmReceiver-\u003echeck(); // will be executed without WrongSignatureException\n\n$usmReceiver\n    -\u003esetSignParams('sign', ['p1', 'p2', 'p3'])\n    -\u003esetSecretKey('123');\n$usmReceiver-\u003echeck(); // will throw WrongSignatureException\n\n$usmSender = UrlSecurityManager::parse($inputUrl)\n    -\u003esetSignParams('sign') // all query params will be signed\n    -\u003esetSecretKey($secretKey)\n    -\u003esign();\n$signedUrl = $usmSender-\u003estringify();\necho $signedUrl;\n// http://localhost:8080/test/path?p1=1\u0026p2=2\u0026p3=3\u0026p4=4\u0026sign=50489186458519f9f141e616dc02af73\n```\n\n##### Encrypting/decrypting\n```php\nuse Smoren\\UrlSecurityManager\\UrlSecurityManager;\n\n$inputUrl = 'http://localhost:8080/test/path?p1=1\u0026p2=2\u0026p3=3\u0026p4=4';\n$secretKey = 'fvd76df89g7fdg89';\n\n// Let's encrypt url with our secret key to send some secret data to receiver:\n$usmSender = UrlSecurityManager::parse($inputUrl)\n    // encrypted string will be stored as value of query param \"encrypted\"\n    // all query params will be encrypted\n    -\u003esetEncryptParams('encrypted') \n    -\u003esetSecretKey($secretKey)\n    -\u003eencrypt(); // encrypting data\n\n$encryptedUrl = $usmSender-\u003estringify();\necho $encryptedUrl;\n// someting like this:\n// http://localhost:8080/test/path?encrypted=X4oxVda3u%2FD2NX...\n\n// Now we will try to decrypt received secret data:\n$usmReceiver = UrlSecurityManager::parse($encryptedUrl)\n    -\u003esetEncryptParams('encrypted')\n    -\u003esetSecretKey($secretKey)\n    -\u003edecrypt();\n\n$decryptedUrl = $usmReceiver-\u003estringify();\necho $decryptedUrl;\n// http://localhost:8080/test/path?p1=1\u0026p2=2\u0026p3=3\u0026p4=4\n\n$usmSender-\u003edecrypt();\n\n// encrypt only query params: p1, p2\n$usmSender-\u003esetEncryptParams('encrypted', ['p1', 'p2']);\n$usmSender-\u003eencrypt();\n\necho $usmSender-\u003estringify();\n// something like this:\n// http://localhost:8080/test/path?p3=3\u0026p4=4\u0026encrypted=CTNdFXZDlBwYwwvQV2L8mGjQg5YydC3...\n\n$usmSender-\u003edecrypt();\necho $usmSender-\u003estringify();\n// http://localhost:8080/test/path?p3=3\u0026p4=4\u0026p1=1\u0026p2=2\n```\n\n##### Building URLs\n```php\nuse Smoren\\UrlSecurityManager\\UrlSecurityManager;\n\n$usm = UrlSecurityManager::create()\n    -\u003esetScheme('https')\n    -\u003esetHost('test.com')\n    -\u003esetPort(8080)\n    -\u003esetPath('/test/path')\n    -\u003esetParams(['a' =\u003e 1, 'b' =\u003e 2]);\n\necho $usm-\u003estringify();\n// https://test.com:8080/test/path?a=1\u0026b=2\n\n$usm\n    -\u003esetSignParams('sign')\n    -\u003esetSecretKey('q1w2e3r4t5y6u7')\n    -\u003esign();\n\necho $usm-\u003estringify();\n// https://test.com:8080/test/path?a=1\u0026b=2\u0026sign=89727a40dc08dc9f12d91b5d6e627c17\n\n$usm = UrlSecurityManager::create([\n    'scheme' =\u003e 'http',\n    'host' =\u003e 'test.com',\n    'port' =\u003e 8080,\n    'path' =\u003e '/test/path',\n    'params' =\u003e ['a' =\u003e 1, 'b' =\u003e 2],\n]);\n\necho $usm-\u003estringify();\n// http://test.com:8080/test/path?a=1\u0026b=2\n```\n\n##### Parse URL from server request\n```php\nuse Smoren\\UrlSecurityManager\\UrlSecurityManager;\n\n$usm = UrlSecurityManager::parse();\n\necho $usm-\u003estringify();\n// you will see full URL of your current server request\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmoren%2Furl-security-manager-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmoren%2Furl-security-manager-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmoren%2Furl-security-manager-php/lists"}