{"id":32610526,"url":"https://github.com/maize-tech/laravel-encryptable","last_synced_at":"2025-10-30T13:50:11.645Z","repository":{"id":41876002,"uuid":"380274841","full_name":"maize-tech/laravel-encryptable","owner":"maize-tech","description":"Easily anonymize sensitive data through eloquent queries","archived":false,"fork":false,"pushed_at":"2025-10-19T14:14:12.000Z","size":378,"stargazers_count":111,"open_issues_count":1,"forks_count":11,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-10-19T22:59:48.143Z","etag":null,"topics":["api","eloquent","encryptable","encryption","laravel","php"],"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/maize-tech.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"maize-tech"}},"created_at":"2021-06-25T15:09:07.000Z","updated_at":"2025-10-19T14:14:15.000Z","dependencies_parsed_at":"2025-09-29T10:10:54.117Z","dependency_job_id":"c73d82ee-9c1f-4eec-ac32-be6be533b231","html_url":"https://github.com/maize-tech/laravel-encryptable","commit_stats":{"total_commits":26,"total_committers":5,"mean_commits":5.2,"dds":0.6153846153846154,"last_synced_commit":"e2e0fb3297f707357f0acc732de2898e0d102861"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/maize-tech/laravel-encryptable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maize-tech%2Flaravel-encryptable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maize-tech%2Flaravel-encryptable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maize-tech%2Flaravel-encryptable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maize-tech%2Flaravel-encryptable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maize-tech","download_url":"https://codeload.github.com/maize-tech/laravel-encryptable/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maize-tech%2Flaravel-encryptable/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281818074,"owners_count":26566858,"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","status":"online","status_checked_at":"2025-10-30T02:00:06.501Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["api","eloquent","encryptable","encryption","laravel","php"],"created_at":"2025-10-30T13:50:10.605Z","updated_at":"2025-10-30T13:50:11.639Z","avatar_url":"https://github.com/maize-tech.png","language":"PHP","readme":"\n\u003cp align=\"center\"\u003e\n\u003cpicture\u003e\n  \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"/art/socialcard-dark.png\"\u003e\n  \u003csource media=\"(prefers-color-scheme: light)\" srcset=\"/art/socialcard-light.png\"\u003e\n  \u003cimg src=\"/art/socialcard-light.png\" alt=\"Social Card of Laravel Encryptable\"\u003e\n\u003c/picture\u003e\n\u003c/p\u003e\n\n# Laravel Encryptable\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/maize-tech/laravel-encryptable.svg?style=flat-square)](https://packagist.org/packages/maize-tech/laravel-encryptable)\n[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/maize-tech/laravel-encryptable/run-tests.yml?branch=main\u0026label=tests\u0026style=flat-square)](https://github.com/maize-tech/laravel-encryptable/actions?query=workflow%3Arun-tests+branch%3Amain)\n[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/maize-tech/laravel-encryptable/php-cs-fixer.yml?branch=main\u0026label=code%20style\u0026style=flat-square)](https://github.com/maize-tech/laravel-encryptable/actions?query=workflow%3A\"Check+%26+fix+styling\"+branch%3Amain)\n[![Total Downloads](https://img.shields.io/packagist/dt/maize-tech/laravel-encryptable.svg?style=flat-square)](https://packagist.org/packages/maize-tech/laravel-encryptable)\n\n\nThis package allows you to anonymize sensitive data (like the name, surname and email address of a user) similarly to Laravel's Encryption feature, but still have the ability to make direct queries to the database.\nAn example use case could be the need to make search queries through anonymized attributes.\n\nThis package currently supports `MySQL` and `PostgreSQL` databases.\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require maize-tech/laravel-encryptable\n```\n\nYou can publish the config file with:\n```bash\nphp artisan vendor:publish --provider=\"Maize\\Encryptable\\EncryptableServiceProvider\" --tag=\"encryptable-config\"\n```\n\nThis is the content of the published config file:\n\n```php\nreturn [\n    /*\n    |--------------------------------------------------------------------------\n    | Encryption key\n    |--------------------------------------------------------------------------\n    |\n    | The key used to encrypt data.\n    | Once defined, never change it or encrypted data cannot be correctly decrypted.\n    |\n    */\n\n    'key' =\u003e env('ENCRYPTION_KEY'),\n\n    /*\n    |--------------------------------------------------------------------------\n    | Encryption cipher\n    |--------------------------------------------------------------------------\n    |\n    | The cipher used to encrypt data.\n    | Once defined, never change it or encrypted data cannot be correctly decrypted.\n    | Default value is the cipher algorithm used by default in MySQL.\n    |\n    */\n\n    'cipher' =\u003e env('ENCRYPTION_CIPHER', 'aes-128-ecb'),\n];\n```\n\n## Usage\n\n### Basic\n\nTo use the package, just add the `Encryptable` cast to all model attributes you want to anonymize.\n\n``` php\n\u003c?php\n\nnamespace App\\Models;\n\nuse Maize\\Encryptable\\Encryptable;\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass User extends Model\n{\n    protected $fillable = [\n        'name',\n        'email',\n    ];\n\n    protected $casts = [\n        'name' =\u003e Encryptable::class,\n        'email' =\u003e Encryptable::class,\n    ];\n}\n```\n\nOnce done, all values will be encrypted before being stored in the database, and decrypted when querying them via Eloquent.\n\n### Manually encrypt via PHP\n\n``` php\nuse Maize\\Encryptable\\Encryption;\n\n$value = \"your-decrypted-value\";\n\n$encrypted = Encryption::php()-\u003eencrypt($value); // returns the encrypted value\n```\n\n### Manually decrypt via PHP\n\n``` php\nuse Maize\\Encryptable\\Encryption;\n\n$encrypted = \"your-encrypted-value\";\n\n$value = Encryption::php()-\u003edecrypt($value); // returns the decrypted value\n```\n\n### Manually decrypt via DB\n\n``` php\nuse Maize\\Encryptable\\Encryption;\n\n$encrypted = \"your-encrypted-value\";\n\n$encryptedQuery = Encryption::db()-\u003eencrypt($value); // returns the query used to find the decrypted value\n```\n\n### Custom validation rules\n\nYou can use one of the two custom rules to check the uniqueness or existence of a given encryptable value.\n\n`ExistsEncrypted` is an extension of Laravel's `Exists` rule, whereas `UniqueEncrypted` is an extension of Laravel's `Unique` rule.\nYou can use them in the same way as Laravel's base rules:\n``` php\nuse Maize\\Encryptable\\Rules\\ExistsEncrypted;\nuse Illuminate\\Support\\Facades\\Validator;\nuse Illuminate\\Validation\\Rule;\n\n$data = [\n    'email' =\u003e 'email@example.com',\n];\n\nValidator::make($data, [\n    'email' =\u003e [\n        'required',\n        'string',\n        'email',\n        new ExistsEncrypted('users'), // checks whether the given email exists in the database\n        Rule::existsEncrypted('users') // alternative way to invoke the rule\n    ],\n]);\n```\n\n``` php\nuse Maize\\Encryptable\\Rules\\UniqueEncrypted;\nuse Illuminate\\Support\\Facades\\Validator;\n\n$data = [\n    'email' =\u003e 'email@example.com',\n];\n\nValidator::make($data, [\n    'email' =\u003e [\n        'required',\n        'string',\n        'email',\n        new UniqueEncrypted('users'), // checks whether the given email does not already exist in the database\n        Rule::uniqueEncrypted('users') // alternative way to invoke the rule\n    ],\n]);\n```\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/maize-tech/.github/blob/main/CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](https://github.com/maize-tech/.github/security/policy) on how to report security vulnerabilities.\n\n## Credits\n\n- [Enrico De Lazzari](https://github.com/enricodelazzari)\n- [Riccardo Dalla Via](https://github.com/riccardodallavia)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","funding_links":["https://github.com/sponsors/maize-tech"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaize-tech%2Flaravel-encryptable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaize-tech%2Flaravel-encryptable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaize-tech%2Flaravel-encryptable/lists"}