{"id":23301587,"url":"https://github.com/jdforsythe/elocryptlumen","last_synced_at":"2026-04-30T03:35:38.760Z","repository":{"id":56997578,"uuid":"56181402","full_name":"jdforsythe/elocryptlumen","owner":"jdforsythe","description":"A port of the great ElocryptFive package for use with Lumen, without having to enable facades","archived":false,"fork":false,"pushed_at":"2016-04-30T02:13:58.000Z","size":9,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-25T20:06:26.798Z","etag":null,"topics":["crypto","decrypt-data","eloquent","encrypted-data","encrypted-values","lumen","lumen-package","php"],"latest_commit_sha":null,"homepage":null,"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/jdforsythe.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":"2016-04-13T19:50:40.000Z","updated_at":"2017-07-06T10:56:00.000Z","dependencies_parsed_at":"2022-08-21T11:10:14.326Z","dependency_job_id":null,"html_url":"https://github.com/jdforsythe/elocryptlumen","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/jdforsythe/elocryptlumen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdforsythe%2Felocryptlumen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdforsythe%2Felocryptlumen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdforsythe%2Felocryptlumen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdforsythe%2Felocryptlumen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jdforsythe","download_url":"https://codeload.github.com/jdforsythe/elocryptlumen/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdforsythe%2Felocryptlumen/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32454127,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T22:27:22.272Z","status":"online","status_checked_at":"2026-04-30T02:00:05.929Z","response_time":57,"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":["crypto","decrypt-data","eloquent","encrypted-data","encrypted-values","lumen","lumen-package","php"],"created_at":"2024-12-20T10:14:37.247Z","updated_at":"2026-04-30T03:35:38.731Z","avatar_url":"https://github.com/jdforsythe.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Eloquent Encryption/Decryption for Lumen 5\n[![Build Status](https://travis-ci.org/jdforsythe/elocryptlumen.svg?branch=master)](https://travis-ci.org/jdforsythe/elocryptlumen.svg?branch=master)\n\nAutomatically encrypt and decrypt Lumen 5 Eloquent values.\n\n## READ THIS FIRST\n\nEncrypted values are usually longer than plain text values.  Sometimes much longer.  You\nmay find that the column widths in your database tables need to be extended to store the\nencrypted values.\n\nIf you are encrypting long strings such as JSON blobs then the encrypted values may be\nlonger than a VARCHAR field can support, and you may need to extend your column types to\nTEXT or LONGTEXT.\n\n## What Does This Do?\n\nThis encrypts and decrypts columns stored in database tables in Lumen applications\ntransparently, by encrypting data as it is stored in the model attributes and decrypting\ndata as it is recalled from the model attributes.\n\nAll data that is encrypted is prefixed with a tag (currently `__ELOCRYPT__;`) so that\nencrypted data can be easily identified.\n\nThis supports columns that store either encrypted or non-encrypted data to make migration\neasier.  Data can be read from columns correctly regardless of whether it is encrypted or\nnot but will be automatically encrypted when it is saved back into those columns.\n\n## Contributors\n\nThis is Del's Laravel 5 Elocrypt package ported so it can be used in Lumen without enabling\nfacades. I have made the following changes:\n\n* Load the `'encrypter'` directly instead of through the `Crypt` facade, enabling use in Lumen\n  without turning on Facades\n\n* Enable setting the elocrypt prefix in the `.env` file (`ELOCRYPT_PREFIX=`)\n\nThe original Laravel 5 package is here: https://github.com/delatbabel/elocrypt\n\nThe original Laravel 4 package is here: https://github.com/dtisgodsson/elocrypt\n\n## Installation\n\nThis package can be installed via Composer by adding the following to your `composer.json` file:\n\n```\n    \"require\": {\n        \"jdforsythe/elocryptlumen\": \"~1.0\"\n    }\n```\n\nYou must then run the following command:\n\n```\n    composer update\n```\n\n## Usage\n\nSimply reference the Elocrypt trait in any Eloquent Model you wish to apply encryption to and define\nan `$encrypts` array containing a list of the attributes to encrypt.\n\nFor example:\n\n```php\n    use Jdforsythe\\ElocryptLumen\\Elocrypt;\n\n    class User extends Eloquent {\n\n        use Elocrypt;\n\n        /**\n         * The attributes that should be encrypted on save.\n         *\n         * @var array\n         */\n        protected $encrypts = [\n            'address_line_1', 'first_name', 'last_name', 'postcode'\n        ];\n    }\n```\n\nYou can combine `$casts` and `$encrypts` to store encrypted arrays.  An array will first be converted to JSON\nand then encrypted.\n\nFor example:\n\n```php\n    use Jdforsythe\\ElocryptLumen\\Elocrypt;\n\n    class User extends Eloquent {\n\n        use Elocrypt;\n\n        protected $casts = ['extended_data' =\u003e 'array'];\n\n        protected $encrypts = ['extended_data'];\n    }\n```\n\n# How it Works?\n\nBy including the Elocrypt trait, the setAttribute() and getAttributeFromArray() methods provided\nby Eloquent are overridden to include an additional step. This additional step simply checks\nwhether the attribute being set or get is included in the `$encrypts` array on the model,\nand either encrypts/decrypts it accordingly.\n\n## Summary of Methods in Illuminate\\Database\\Eloquent\\Model\n\nThis surveys the major methods in the Eloquent Model class as of\nLaravel v 5.1.12 and checks to see how those models set attributes\nand hence how they are affected by this trait.\n\n* constructor -- calls fill()\n* fill() -- calls setAttribute() which has been extended to encrypt the data.\n* hydrate() -- TBD\n* create() -- calls constructor and hence fill()\n* firstOrCreate -- calls constructor\n* firstOrNew -- calls constructor\n* updateOrCreate -- calls fill()\n* update() -- calls fill()\n* toArray() -- calls attributesToArray()\n* jsonSerialize() -- calls toArray()\n* toJson() -- calls toArray()\n* attributesToArray() -- calls getArrayableAttributes().\n* getAttribute -- calls getAttributeValue()\n* getAttributeValue -- calls getAttributeFromArray()\n* getAttributeFromArray -- calls getArrayableAttributes()\n* getArrayableAttributes -- has been extended here to decrypt the data.\n* setAttribute -- has been extended here to encrypt the data.\n* getAttributes -- has been extended here to decrypt the data.\n\n## Keys and IVs\n\nThe key for the Lumen Encrypter service is set in the `.env` file as `APP_KEY`. Lumen defaults to AES-256-CBC\ncipher.\n\nThe IV for encryption is randomly generated.\n\n# FAQ\n\n## Manually Encrypting Data\n\nYou can manually encrypt or decrypt data using the `encryptedAttribute()` and `decryptedAttribute()` functions.\nAn example is as follows:\n\n```php\n    $user = new User();\n    $encryptedEmail = $user-\u003eencryptedAttribute(Input::get(\"email\"));\n```\n\n## Encryption and Searching\n\nYou will not be able to search on encrypted data, because it is encrypted.  Comparing encrypted values\nwould require a fixed IV which introduces security issues.\n\nIf you need to search on data then either:\n\n* Leave it unencrypted, or\n* Hash the data and search on the hash instead of the encrypted value.  Use a well known hash algorithm\n  such as SHA256.\n\nYou could store both a hashed and an encrypted value, use the hashed value for searching and retrieve\nthe encrypted value for other uses.\n\n## Encryption and Authentication\n\nThe same problem with searching applies for authentication because authentication requires a user search.\n\nIf you have an authentication table where you encrypt the user data including the login data (for example the email),\nthis will prevent Auth::attempt from working.  For example this code will not work:\n\n```php\n    $auth = Auth::attempt(array(\n                \"email\"     =\u003e  Input::get(\"email\"),\n                \"password\"  =\u003e  Input::get(\"password\"),\n    ), $remember);\n```\n\nAs for searching, comparing the encrypted email will not work, because it would require a fixed IV\nwhich introduces security issues.\n\nWhat you will need to do instead is to hash the email address using a well known hash function (e.g.\nSHA256 or RIPE-MD160) rather than encrypt it, and then in the Auth::attempt function you can compare\nthe hashes.\n\nIf you need access to the email address then you could store both a hashed and an encrypted email\naddress, use the hashed value for authentication and retrieve the encrypted value for other uses\n(e.g. sending emails).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjdforsythe%2Felocryptlumen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjdforsythe%2Felocryptlumen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjdforsythe%2Felocryptlumen/lists"}