{"id":13622831,"url":"https://github.com/jenssegers/optimus","last_synced_at":"2025-04-11T03:29:56.728Z","repository":{"id":31422416,"uuid":"34985876","full_name":"jenssegers/optimus","owner":"jenssegers","description":"🤖 Id obfuscation based on Knuth's multiplicative hashing method for PHP.","archived":false,"fork":false,"pushed_at":"2024-03-27T22:24:53.000Z","size":2520,"stargazers_count":1268,"open_issues_count":14,"forks_count":74,"subscribers_count":27,"default_branch":"master","last_synced_at":"2024-10-29T23:33:23.533Z","etag":null,"topics":["hashids","ids","laravel","obfuscation","optimus","transformations"],"latest_commit_sha":null,"homepage":"https://jenssegers.com","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/jenssegers.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","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},"funding":{"github":["jenssegers"],"tidelift":"packagist/jenssegers/optimus"}},"created_at":"2015-05-03T12:51:18.000Z","updated_at":"2024-10-26T00:37:58.000Z","dependencies_parsed_at":"2024-03-29T17:51:42.715Z","dependency_job_id":"95c8b9fb-48bf-4a21-9a1f-d8c28bfe2f44","html_url":"https://github.com/jenssegers/optimus","commit_stats":{"total_commits":105,"total_committers":21,"mean_commits":5.0,"dds":0.4666666666666667,"last_synced_commit":"1abd675bf7717b0a7118e1028e31fa5e5ff23332"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jenssegers%2Foptimus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jenssegers%2Foptimus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jenssegers%2Foptimus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jenssegers%2Foptimus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jenssegers","download_url":"https://codeload.github.com/jenssegers/optimus/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247981835,"owners_count":21028004,"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":["hashids","ids","laravel","obfuscation","optimus","transformations"],"created_at":"2024-08-01T21:01:24.621Z","updated_at":"2025-04-11T03:29:56.707Z","avatar_url":"https://github.com/jenssegers.png","language":"PHP","funding_links":["https://github.com/sponsors/jenssegers","https://tidelift.com/funding/github/packagist/jenssegers/optimus","https://tidelift.com/security"],"categories":["Table of Contents","PHP","目录","安全 Security","\u003ca id=\"1d9dec1320a5d774dc8e0e7604edfcd3\"\u003e\u003c/a\u003e工具-新添加的"],"sub_categories":["Security","安全 Security","\u003ca id=\"8f1b9c5c2737493524809684b934d49a\"\u003e\u003c/a\u003e文章\u0026\u0026视频","Globalization"],"readme":"# Optimus id transformation\n\n[![Packagist](https://badgen.net/packagist/v/jenssegers/optimus)](https://packagist.org/packages/jenssegers/optimus)\n[![Downloads](https://badgen.net/packagist/dt/jenssegers/optimus)](https://packagist.org/packages/jenssegers/optimus/stats)\n[![Build](https://github.com/jenssegers/optimus/workflows/tests/badge.svg)](https://github.com/jenssegers/optimus/actions) \n[![Coverage](http://img.shields.io/coveralls/jenssegers/optimus.svg)](https://coveralls.io/r/jenssegers/optimus?branch=master)\n\nWith this library, you can transform your internal id's to obfuscated integers based on Knuth's integer hash. It is similar to Hashids, but will generate integers instead of random strings. It is also super fast.\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://jenssegers.com/static/media/optimus.png\"\u003e\n\u003c/p\u003e\n\n## Installation\n\nInstall using composer:\n\n```bash\ncomposer require jenssegers/optimus\n```\n\nIf you will be running your code on a 32 bit system or will be working with large prime numbers it is suggested that you install the [GMP extension](http://php.net/manual/en/book.gmp.php). \nFor debian/ubuntu you can install the extension with one of these commands:\n\n```bash\napt-get install php7.4-gmp\napt-get install php8.0-gmp\napt-get install php8.1-gmp\n```\n\n## Usage\n\nTo get started you will need 3 things;\n\n - Large prime number lower than `2147483647`\n - The inverse prime so that `(PRIME * INVERSE) \u0026 MAXID == 1`\n - A large random integer lower than `2147483647`\n\nLuckily for you, I have included a console command that can do all of this for you. To get started, just run the following command:\n\n```bash\n\u003e php vendor/bin/optimus spark\n\nPrime: 2123809381\nInverse: 1885413229\nRandom: 146808189\n```\n\nIf you prefer to choose your own prime number (from [this list](http://primes.utm.edu/lists/small/millions/) for example), you can pass it to the command to calculate the remaining numbers:\n\n```bash\n\u003e php vendor/bin/optimus spark 1580030173\n\nPrime: 1580030173\nInverse: 59260789\nRandom: 1163945558\n```\n\nUsing those numbers, you can start creating instances of `Optimus($prime, $inverted, $random)`:\n\n```php\nuse Jenssegers\\Optimus\\Optimus;\n\nnew Optimus(1580030173, 59260789, 1163945558);\n```\n\n**NOTE**: Make sure that you are using the same constructor values throughout your entire application!\n\n## Encoding and decoding\n\nTo encode id's, use the `encode` method:\n\n```php\n$encoded = $optimus-\u003eencode(20); // 1535832388\n```\n\nTo decode the resulting `1535832388` back to its original value, use the `decode` method:\n\n```php\n$original = $optimus-\u003edecode(1535832388); // 20\n```\n\n## Framework Integrations\n\n### Laravel\n\nThis is an example service provider which registers a shared Optimus instance for your entire application:\n\n```php\n\u003c?php\n\nnamespace App\\Providers;\n\nuse Jenssegers\\Optimus\\Optimus;\nuse Illuminate\\Support\\ServiceProvider;\n\nclass OptimusServiceProvider extends ServiceProvider\n{\n    public function register()\n    {\n        $this-\u003eapp-\u003esingleton(Optimus::class, function ($app) {\n            return new Optimus(1580030173, 59260789, 1163945558);\n        });\n    }\n}\n```\n\nOnce you have created the service provider, add it to the providers array in your `config/app.php` configuration file:\n\n```\nApp\\Providers\\OptimusServiceProvider::class,\n```\n\n\nLaravel's automatic injection will pass this instance where needed. Example controller:\n\n```php\n\u003c?php\n\nnamespace App\\Http\\Controllers;\n\nuse Jenssegers\\Optimus\\Optimus;\nuse App\\Http\\Controllers\\Controller;\n\nclass UserController extends Controller\n{\n    public function show($id, Optimus $optimus)\n    {\n        $id = $optimus-\u003edecode($id);\n    }\n}\n```\n\nMore information: https://laravel.com/docs/5.3/container#resolving\n\n**Third-party integrations**\n\n* An integration with Laravel is provided by the [propaganistas/laravel-fakeid](https://packagist.org/packages/propaganistas/laravel-fakeid) package.\n* Laravel Optimus with multiple connections provided by the [cybercog/laravel-optimus](https://github.com/cybercog/laravel-optimus) package.\n* An integration with Silex 2 is provided by the [jaam/silex-optimus-provider](https://packagist.org/packages/jaam/silex-optimus-provider) package.\n* An integration with Laravel is provided by the [elfsundae/laravel-hashid](https://github.com/ElfSundae/laravel-hashid) package.\n* A PSR-15 middleware provided by the [icanhazstring/optimus-middleware](https://github.com/icanhazstring/optimus-middleware) package.\n\n## Security contact information\n\nTo report a security vulnerability, follow [these steps](https://tidelift.com/security).\n\n## License\n\nThe [MIT](https://opensource.org/licenses/MIT) License.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjenssegers%2Foptimus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjenssegers%2Foptimus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjenssegers%2Foptimus/lists"}