{"id":13540311,"url":"https://github.com/elfsundae/laravel-hashid","last_synced_at":"2025-04-02T07:30:52.265Z","repository":{"id":25704245,"uuid":"106044131","full_name":"ElfSundae/laravel-hashid","owner":"ElfSundae","description":"Obfuscate your data by generating reversible, non-sequential, URL-safe identifiers.","archived":false,"fork":false,"pushed_at":"2024-10-28T16:55:50.000Z","size":151,"stargazers_count":409,"open_issues_count":4,"forks_count":36,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-22T08:02:45.901Z","etag":null,"topics":["base62","base64","encryption","hashids","laravel","obfuscate","optimus","reversible","urlsafe"],"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/ElfSundae.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"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,"publiccode":null,"codemeta":null}},"created_at":"2017-10-06T19:46:35.000Z","updated_at":"2025-03-06T21:32:59.000Z","dependencies_parsed_at":"2024-01-15T05:09:50.850Z","dependency_job_id":"be4c885c-57bd-4ea4-8d8f-a5138305a6b3","html_url":"https://github.com/ElfSundae/laravel-hashid","commit_stats":{"total_commits":231,"total_committers":4,"mean_commits":57.75,"dds":"0.012987012987012991","last_synced_commit":"c02626235eb14453bb7fdb104bf8009a87606e29"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ElfSundae%2Flaravel-hashid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ElfSundae%2Flaravel-hashid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ElfSundae%2Flaravel-hashid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ElfSundae%2Flaravel-hashid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ElfSundae","download_url":"https://codeload.github.com/ElfSundae/laravel-hashid/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246774277,"owners_count":20831504,"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":["base62","base64","encryption","hashids","laravel","obfuscate","optimus","reversible","urlsafe"],"created_at":"2024-08-01T09:01:46.263Z","updated_at":"2025-04-02T07:30:48.364Z","avatar_url":"https://github.com/ElfSundae.png","language":"PHP","funding_links":[],"categories":["\u003ca id=\"783f861b9f822127dba99acb55687cbb\"\u003e\u003c/a\u003e工具"],"sub_categories":["\u003ca id=\"85bb0c28850ffa2b4fd44f70816db306\"\u003e\u003c/a\u003e混淆器\u0026\u0026Obfuscate"],"readme":"# Laravel Hashid\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/elfsundae/laravel-hashid.svg?style=flat-square)](https://packagist.org/packages/elfsundae/laravel-hashid)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)\n[![tests](https://github.com/ElfSundae/laravel-hashid/actions/workflows/tests.yml/badge.svg)](https://github.com/ElfSundae/laravel-hashid/actions/workflows/tests.yml)\n[![StyleCI](https://styleci.io/repos/106044131/shield)](https://styleci.io/repos/106044131)\n[![SymfonyInsight Grade](https://img.shields.io/symfony/i/grade/5ecfdb3d-b2c4-47ca-b50b-4f041fe42f4f?style=flat-square)](https://insight.symfony.com/projects/5ecfdb3d-b2c4-47ca-b50b-4f041fe42f4f)\n[![Quality Score](https://img.shields.io/scrutinizer/g/ElfSundae/laravel-hashid.svg?style=flat-square)](https://scrutinizer-ci.com/g/ElfSundae/laravel-hashid)\n[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/ElfSundae/laravel-hashid/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/ElfSundae/laravel-hashid/?branch=master)\n[![Total Downloads](https://img.shields.io/packagist/dt/elfsundae/laravel-hashid.svg?style=flat-square)](https://packagist.org/packages/elfsundae/laravel-hashid)\n\nLaravel Hashid provides a unified API across various drivers such as [Base62], [Base64], [Hashids] and [Optimus], with support for multiple connections or different encoding options. It offers a simple, elegant way to obfuscate your data by generating reversible, non-sequential, URL-safe identifiers.\n\n\u003c!-- MarkdownTOC --\u003e\n\n- [Installation](#installation)\n- [Configuration](#configuration)\n- [Usage](#usage)\n- [Built-in Drivers](#built-in-drivers)\n    - [Base62](#base62)\n    - [Base64](#base64)\n    - [Hashids](#hashids)\n    - [Hex](#hex)\n    - [Optimus](#optimus)\n- [Custom Drivers](#custom-drivers)\n- [Testing](#testing)\n- [License](#license)\n\n\u003c!-- /MarkdownTOC --\u003e\n\n## Installation\n\nYou can install this package using the [Composer](https://getcomposer.org) manager:\n\n```sh\n$ composer require elfsundae/laravel-hashid\n```\n\nFor Lumen or earlier Laravel than v5.5, you need to register the service provider manually:\n\n```php\nElfSundae\\Laravel\\Hashid\\HashidServiceProvider::class\n```\n\nThen publish the configuration file:\n\n```sh\n# For Laravel application:\n$ php artisan vendor:publish --tag=hashid\n\n# For Lumen application:\n$ cp vendor/elfsundae/laravel-hashid/config/hashid.php config/hashid.php\n```\n\n## Configuration\n\nOur well documented configuration file is extremely similar to the configurations of numerous Laravel manager integrations such as Database, Queue, Cache and Filesystem. So you do not need to spend extra time to learn how to configure Hashid.\n\nAdditionally, for simplicity you do not need to add singleton drivers like Base64 to your config file as they have no encoding options, unless you would like to specify a meaningful connection name.\n\nLet's see an example of the configuration:\n\n```php\n'default' =\u003e 'id',\n\n'connections' =\u003e [\n\n    'basic' =\u003e [\n        'driver' =\u003e 'base64',\n    ],\n\n    'hashids' =\u003e [\n        'driver' =\u003e 'hashids',\n        'salt' =\u003e 'sweet girl',\n    ],\n\n    'id' =\u003e [\n        'driver' =\u003e 'hashids_integer',\n        'salt' =\u003e 'My Application',\n        'min_length' =\u003e 6,\n        'alphabet' =\u003e '1234567890abcdef',\n    ],\n\n    'base62' =\u003e [\n        'driver' =\u003e 'base62',\n        'characters' =\u003e 'f9FkqDbzmn0QRru7PBVeGl5pU28LgIvYwSydK41sCO3htaicjZoWAJNxH6EMTX',\n    ],\n\n],\n```\n\n## Usage\n\nThe `hashid()` helper or the `Hashid` facade may be used to interact with any of your configured connections or drivers:\n\n```php\nuse ElfSundae\\Laravel\\Hashid\\Facades\\Hashid;\n\n// Obtain the default connection instance\nhashid();\nHashid::connection();\n\n// Obtain the \"base62\" connection instance\nhashid('base62');\nHashid::connection('base62');\n\n// Obtain the Base64 driver instance\nhashid('base64');\nHashid::connection('base64');\nHashid::driver('base64');\n```\n\nThere are only two methods you need to know to use any connection or driver:\n\n - `encode($data)` for encoding data.\n - `decode($data)` for decoding data.\n\n```php\nhashid()-\u003eencode(123456);\n\nhashid('base64')-\u003edecode('TGFyYXZlbA');\n\nHashid::encode(123456);\n\nHashid::connection('hashids')-\u003edecode('X68fkp');\n```\n\nAnd there are also two corresponding helper functions:\n\n- `hashid_encode($data, $name = null)`\n- `hashid_decode($data, $name = null)`\n\n```php\nhashid_encode(123456);\n\nhashid_decode('TGFyYXZlbA', 'base64');\n```\n\n## Built-in Drivers\n\n#### Base62\n\n- Drivers: `base62` , `base62_integer`\n- Configuration:\n    - `characters` : 62 unique characters\n- Backend: [`tuupola/base62`][base62]\n- Notes:\n    - You may use the `hashid:alphabet` command to generate random characters.\n    - [GMP] is strongly recommended as it is much faster than pure PHP.\n\n#### Base64\n\n- Drivers: `base64` , `base64_integer`\n- Backend: [`elfsundae/urlsafe-base64`][base64]\n\n#### Hashids\n\n- Drivers: `hashids` , `hashids_hex` , `hashids_integer` , `hashids_string`\n- Configuration:\n    - `salt`\n    - `min_length`\n    - `alphabet` : At least 16 unique characters\n- Backend: [`hashids/hashids`][hashids]\n- Notes:\n    - You may use the `hashid:alphabet` command to generate a random alphabet.\n    - [GMP] is strongly recommended.\n\n#### Hex\n\n- Drivers: `hex` , `hex_integer`\n\n#### Optimus\n\n- Drivers: `optimus`\n- Configuration:\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- Backend: [`jenssegers/optimus`][optimus]\n- Notes:\n    - You may use the `hashid:optimus` command to generate needed numbers.\n    - Only for integer numbers.\n    - The max number can be handled correctly is `2147483647`.\n\n## Custom Drivers\n\nTo create a custom Hashid driver, you only need to implement the [`ElfSundae\\Laravel\\Hashid\\DriverInterface`](src/DriverInterface.php) interface that contains two methods: `encode` and `decode`. The constructor can optionally receive the driver configuration from a `$config` argument, and type-hinted dependencies injection is supported as well:\n\n```php\n\u003c?php\n\nnamespace App\\Hashid;\n\nuse ElfSundae\\Laravel\\Hashid\\DriverInterface;\nuse Illuminate\\Contracts\\Encryption\\Encrypter;\n\nclass CustomDriver implements DriverInterface\n{\n    protected $encrypter;\n\n    protected $serialize;\n\n    public function __construct(Encrypter $encrypter, array $config = [])\n    {\n        $this-\u003eencrypter = $encrypter;\n\n        $this-\u003eserialize = $config['serialize'] ?? false;\n    }\n\n    public function encode($data)\n    {\n        return $this-\u003eencrypter-\u003eencrypt($data, $this-\u003eserialize);\n    }\n\n    public function decode($data)\n    {\n        return $this-\u003eencrypter-\u003edecrypt($data, $this-\u003eserialize);\n    }\n}\n```\n\nNow you can configure the connection with this driver:\n\n```php\n'connections' =\u003e [\n\n    'custom' =\u003e [\n        'driver' =\u003e App\\Hashid\\CustomDriver::class,\n        'serialize' =\u003e false,\n    ],\n\n    // ...\n]\n```\n\nIf you prefer a short name for your driver, just register a container binding with `hashid.driver.` prefix:\n\n```php\n$this-\u003eapp-\u003ebind('hashid.driver.custom', CustomDriver::class);\n```\n\n## Testing\n\n```sh\n$ composer test\n```\n\n## License\n\nThis package is open-sourced software licensed under the [MIT License](LICENSE.md).\n\n[base62]: https://github.com/tuupola/base62\n[base64]: https://github.com/ElfSundae/urlsafe-base64\n[hashids]: https://github.com/ivanakimov/hashids.php\n[optimus]: https://github.com/jenssegers/optimus\n[gmp]: https://secure.php.net/gmp\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felfsundae%2Flaravel-hashid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felfsundae%2Flaravel-hashid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felfsundae%2Flaravel-hashid/lists"}