{"id":13684566,"url":"https://github.com/usemuffin/obfuscate","last_synced_at":"2025-12-28T10:46:15.006Z","repository":{"id":54787706,"uuid":"49851077","full_name":"UseMuffin/Obfuscate","owner":"UseMuffin","description":"ID obfuscation for the CakePHP ORM.","archived":false,"fork":false,"pushed_at":"2023-09-27T03:14:52.000Z","size":79,"stargazers_count":36,"open_issues_count":0,"forks_count":11,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-09-25T06:11:12.278Z","etag":null,"topics":[],"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/UseMuffin.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-01-18T04:02:02.000Z","updated_at":"2023-09-27T02:43:44.000Z","dependencies_parsed_at":"2024-01-22T07:48:01.869Z","dependency_job_id":"2aeaae2a-6335-4fa2-afa3-b1ff8be9103f","html_url":"https://github.com/UseMuffin/Obfuscate","commit_stats":{"total_commits":63,"total_committers":8,"mean_commits":7.875,"dds":0.6349206349206349,"last_synced_commit":"1613427e90655c7d6736fa4477275734b3be6432"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UseMuffin%2FObfuscate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UseMuffin%2FObfuscate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UseMuffin%2FObfuscate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UseMuffin%2FObfuscate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/UseMuffin","download_url":"https://codeload.github.com/UseMuffin/Obfuscate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224224797,"owners_count":17276428,"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-08-02T14:00:34.956Z","updated_at":"2025-12-28T10:46:14.943Z","avatar_url":"https://github.com/UseMuffin.png","language":"PHP","funding_links":[],"categories":["Security","Plugins"],"sub_categories":["Security"],"readme":"# Obfuscate\n\n[![Build Status](https://img.shields.io/github/actions/workflow/status/UseMuffin/Obfuscate/ci.yml?style=flat-square\u0026branch=master\n)](https://github.com/UseMuffin/Obfuscate/actions?query=workflow%3ACI+branch%3Amaster)\n[![Coverage Status](https://img.shields.io/codecov/c/github/UseMuffin/Obfuscate.svg?style=flat-square)](https://codecov.io/github/UseMuffin/Obfuscate)\n[![Total Downloads](https://img.shields.io/packagist/dt/muffin/obfuscate.svg?style=flat-square)](https://packagist.org/packages/muffin/obfuscate)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE)\n\nPrimary key obfuscation for CakePHP using HashIds, Optimus, Base62 and/or custom obfuscation strategies.\n\n## Installation\n\nInstall the plugin using [Composer](https://getcomposer.org):\n\n```\ncomposer require muffin/obfuscate\n```\n\nLoad the plugin by either running this console command:\n\n```\nbin/cake plugin load Muffin/Obfuscate\n```\n\nor by manually adding the following line to `src/Application.php`:\n\n```php\n$this-\u003eaddPlugin('Muffin/Obfuscate');\n```\n\nLastly, install the required obfuscation library depending on the strategy class\nyou want to use and stated below.\n\n## Built-in obfuscation strategies\n\nUse the [HashIdStrategy](http://hashids.org/) if you want to:\n\n- obfuscate your primary keys with short, unique, non-sequential ids\n- present record ids like 347 as strings like “yr8”\n\n```\ncomposer require hashids/hashids\n```\n\nUse the [OptimusStrategy](https://github.com/jenssegers/optimus) if you want to:\n\n- obfuscate your primary keys with integers based on Knuth's integer hash\n- present record ids like 347 as integers like 372555994\n\n```\ncomposer require jenssegers/optimus\n```\n\nUse the [Base62Strategy](https://github.com/tuupola/base62) if you want to:\n\n- obfuscate your primary keys with base62 strings and integers\n- present record ids like 347 as strings like \"vk\"\n\n```\ncomposer require tuupola/base62\n```\n\nYou can also create your own strategy classes by implementing the `StrategyInterface`.\n\n## Usage\n\n### 1. Attaching the behavior\n\nPrepare for obfuscation by attaching the Obfuscate behavior to your table(s)\nand specifying which strategy you want to use as shown in the following examples.\n\n```php\nuse Muffin\\Obfuscate\\Model\\Behavior\\Strategy\\HashIdStrategy;\n\n$this-\u003eaddBehavior('Muffin/Obfuscate.Obfuscate', [\n    // Strategy constructor parameter:\n    // $salt - Random alpha numeric string. You can also set \"Obfuscate.salt\"\n    // $minLength (optional) - The minimum hash length. Default: 0\n    // $alphabet (optional) - Custom alphabet to generate hash from. Default: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'\n    // config instead of passing salt to construction.\n    // DO NOT USE same salt as set for \"Security.salt\" config.\n    'strategy' =\u003e new HashIdStrategy('5SX0TEjkR1mLOw8Gvq2VyJxIFhgCAYidrclDWaM3so9bfzZpuUenKtP74QNH6B', 10, 'abcdefghijklmnopqrstuvwxyz')\n]);\n```\n\n```php\nuse Muffin\\Obfuscate\\Model\\Behavior\\Strategy\\OptimusStrategy;\n\n$this-\u003eaddBehavior('Muffin/Obfuscate.Obfuscate', [\n    // Strategy constructor parameters:\n    // $prime - Large prime number lower than 2147483647\n    // $inverse - The inverse prime so that (PRIME * INVERSE) \u0026 MAXID == 1\n    // $random - A large random integer lower than 2147483647\n    // You can use vendor/bin/optimus spark to generate these set of numbers.\n    'strategy' =\u003e new OptimusStrategy(2123809381, 1885413229, 146808189)\n]);\n```\n\n```php\nuse Muffin\\Obfuscate\\Model\\Behavior\\Strategy\\Base62Strategy;\n\n$this-\u003eaddBehavior('Muffin/Obfuscate.Obfuscate', [\n    // Strategy constructor parameters:\n    // $set - Random alpha-numeric set where each character must only be used exactly once\n    'strategy' =\u003e new Base62Strategy('5SX0TEjkR1mLOw8Gvq2VyJxIFhgCAYidrclDWaM3so9bfzZpuUenKtP74QNH6B')\n]);\n```\n\n\u003e Please note that attaching the behavior is totally unobtrusive and will do\n\u003e absolutely nothing until you use one of the custom finders.\n\n### 2. Using the custom finders\n\nThis plugin comes with the following two custom finders that are responsible for\nthe actual obfuscation (cloaking) and elucidation (uncloaking) process:\n\n- `findObfuscated`: used to find records using an obfuscated (cloaked) primary key\n- `findObfuscate`: used to obfuscate (cloak) all primary keys in a find result set\n\n### findObfuscated\n\nUse this finder if you want to look up a record using an obfuscated id.\nThe plugin will elucidate (uncloak) the obfuscated id and will execute the find\nusing the \"normal\" primary key as it is used inside your database.\n\nCakePHP example:\n```php\npublic function view($id)\n{\n    $article = $this-\u003eArticles-\u003efind('obfuscated')\n        -\u003ewhere(['id' =\u003e $id]) // For e.g. if value for $id is 'S' it will search for actual id 1\n        -\u003efirst();\n}\n```\n\nCrud plugin example:\n```php\npublic function view($id)\n{\n    $this-\u003eCrud-\u003eon('beforeFind', function (EventInterface $event) {\n        $event-\u003esubject()-\u003equery-\u003efind('obfuscated');\n    });\n}\n```\n\n#### findObfuscate\n\nUse this finder if you want the plugin to obfuscate all \"normal\" primary keys\nfound in a find result set.\n\nCakePHP example:\n```php\npublic function index()\n{\n    $articles = $this-\u003eArticles-\u003efind('obfuscate');\n}\n```\n\nCrud plugin example:\n```php\npublic function index()\n{\n    $this-\u003eCrud-\u003eon('beforePaginate', function (EventInterface $event) {\n        $event-\u003esubject()-\u003equery-\u003efind('obfuscate');\n    });\n}\n```\n\n### Methods\n\nAttaching the behavior also makes the following two methods available on the table:\n\n- `obfuscate(string $str)`\n- `elucidate(string $str)`\n\n## Pro tips\n\n### Authentication\n\nA fairly common use case is applying obfuscation to user ids. To ensure the\nAuthentication plugin properly handles obfuscated ids, specify the `obfuscated` finder\nusing the `finder` key in your [identifier's resolver](https://book.cakephp.org/authentication/3/en/identifiers.html) config.\n\n## Patches \u0026 Features\n\n* Fork\n* Mod, fix\n* Test - this is important, so it's not unintentionally broken\n* Commit - do not mess with license, todo, version, etc. (if you do change any, bump them into commits of\ntheir own that I can ignore when I pull)\n* Pull request - bonus point for topic branches\n\nTo ensure your PRs are considered for upstream, you MUST follow the [CakePHP coding standards][standards].\n\n## Bugs \u0026 Feedback\n\nhttp://github.com/usemuffin/obfuscate/issues\n\n## License\n\nCopyright (c) 2015-Present, [Use Muffin][muffin] and licensed under [The MIT License][mit].\n\n[cakephp]:http://cakephp.org\n[composer]:http://getcomposer.org\n[mit]:http://www.opensource.org/licenses/mit-license.php\n[muffin]:http://usemuffin.com\n[standards]:http://book.cakephp.org/5.0/en/contributing/cakephp-coding-conventions.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fusemuffin%2Fobfuscate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fusemuffin%2Fobfuscate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fusemuffin%2Fobfuscate/lists"}