{"id":24206271,"url":"https://github.com/bespredel/encryption-form","last_synced_at":"2026-04-25T18:00:54.132Z","repository":{"id":267931420,"uuid":"902780575","full_name":"BespredeL/encryption-form","owner":"BespredeL","description":"A Laravel package to securely encrypt form fields on the client-side using public key encryption and decrypt them on the server-side using the private key.","archived":false,"fork":false,"pushed_at":"2026-04-19T06:48:31.000Z","size":169,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-04-19T08:33:40.180Z","etag":null,"topics":["client-side-encryption","data-privacy","encryption","form-encryption","laravel","open-source","php","privacy-protection","rsa-encryption","security"],"latest_commit_sha":null,"homepage":"https://bespredel.name","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/BespredeL.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":"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}},"created_at":"2024-12-13T08:56:26.000Z","updated_at":"2026-04-19T06:48:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"757b34b0-f586-4f4d-86a7-6bc6bb37c7c4","html_url":"https://github.com/BespredeL/encryption-form","commit_stats":null,"previous_names":["bespredel/encryption-form"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/BespredeL/encryption-form","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BespredeL%2Fencryption-form","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BespredeL%2Fencryption-form/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BespredeL%2Fencryption-form/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BespredeL%2Fencryption-form/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BespredeL","download_url":"https://codeload.github.com/BespredeL/encryption-form/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BespredeL%2Fencryption-form/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32271243,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-25T09:15:33.318Z","status":"ssl_error","status_checked_at":"2026-04-25T09:15:31.997Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["client-side-encryption","data-privacy","encryption","form-encryption","laravel","open-source","php","privacy-protection","rsa-encryption","security"],"created_at":"2025-01-14T00:19:54.888Z","updated_at":"2026-04-25T18:00:54.126Z","avatar_url":"https://github.com/BespredeL.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# EncryptionForm - Secure Client-Side Form Encryption\n\n[![Readme EN](https://img.shields.io/badge/README-EN-blue.svg)](https://github.com/bespredel/encryption-form/blob/master/README.md)\n[![Readme RU](https://img.shields.io/badge/README-RU-blue.svg)](https://github.com/bespredel/encryption-form/blob/master/README_RU.md)\n[![GitHub license](https://img.shields.io/badge/license-MIT-458a7b.svg)](https://github.com/bespredel/encryption-form/blob/master/LICENSE)\n[![Downloads](https://img.shields.io/packagist/dt/bespredel/encryption-form.svg)](https://packagist.org/packages/bespredel/encryption-form)\n\n[![Latest Version](https://img.shields.io/github/v/release/bespredel/encryption-form?logo=github)](https://github.com/bespredel/encryption-form/releases)\n[![Latest Version Packagist](https://img.shields.io/packagist/v/bespredel/encryption-form.svg?logo=packagist\u0026logoColor=white\u0026color=F28D1A)](https://packagist.org/packages/bespredel/encryption-form)\n[![PHP from Packagist](https://img.shields.io/packagist/php-v/bespredel/encryption-form.svg?logo=php\u0026logoColor=white\u0026color=777BB4)](https://php.net)\n[![Laravel Version](https://img.shields.io/badge/laravel-%3E%3D9-FF2D20?logo=laravel)](https://laravel.com)\n\n🔐 Protect sensitive form data before it leaves the browser\n\nEncryptionForm is a lightweight solution for encrypting form data on the client side before sending it to the server.\n\nIt helps protect sensitive information such as **passwords, personal data, and confidential inputs from interception.**\n\n---\n\n## ✨ Features\n\n- **RSA Encryption**: Uses `JSEncrypt` for secure RSA encryption.\n- **HTML Attribute Control**: Specify which fields to encrypt using `data-encrypt=\"true\"`.\n- **Flexible Form Encryption**: Target specific forms using `data-encrypt-form` attribute.\n- **Blade Directive**: Automatically inject encryption scripts with `@encryptFormScripts`.\n- **Simple Key Management**: Easily configure keys via `.env` or generate new keys via artisan commands.\n- **Zero Dependencies**: No NPM required; all scripts are included in the package.\n\n---\n\n## 🚀 Use Cases\n\n- Login \u0026 authentication forms\n- Payment / sensitive input fields\n- Personal data collection forms\n- Secure admin panels\n- API request protection\n\n---\n\n## 🧠 How It Works\n\n1. User fills the form\n2. Data is encrypted in the browser\n3. Encrypted payload is sent to server\n4. Server decrypts the data\n5. Application processes secure input\n\n---\n\n## 📦 Installation\n\n1. **Install the Package**:\n   ```bash\n   composer require bespredel/encryption-form\n   ```\n2. **Publish Config and Scripts**:\n   ```bash\n   php artisan vendor:publish --tag=encryption-form\n   ```\n3. **Add RSA Keys to ```.env```**:\n   ```bash\n   ENCRYPTION_FORM_PUBLIC_KEY=\"-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----\"\n   ENCRYPTION_FORM_PRIVATE_KEY=\"-----BEGIN PRIVATE KEY-----...-----END PRIVATE KEY-----\"\n   ```\n\n   If you don't have keys, you can generate them using the following commands:\n   ```bash\n   php artisan encryption-form:generate-keys\n   ```\n\n4. **Include the Blade Directive in Your Template**:\n   Add `@encryptFormScripts` to your layout file or specific views where forms are encrypted.\n\n---\n\n## 🚀 Usage\n\n### Middleware\n\nFor auto decryption of form data, add the `DecryptRequestFields` middleware to your `Kernel`:\n\n```php\nAdd the middleware to your Kernel\n\nprotected $middleware = [\n    // Other middleware\n    \\Bespredel\\EncryptionForm\\Middleware\\DecryptRequestFields::class\n]\n```\n\nor use it in a route:\n\n```php\nRoute::middleware('decrypt-form')-\u003egroup(function () {\n    // Your code\n})\n```\n\n### HTML Form Example\n\nIn your Blade template:\n\n```html\n\n\u003chead\u003e\n    @encryptFormStyles\n    @encryptFormScripts\n\u003c/head\u003e\n\n\u003cform data-encrypt-form action=\"/submit\" method=\"POST\"\u003e\n    \u003cinput type=\"text\" name=\"name\" data-encrypt=\"true\" placeholder=\"Enter your name\" /\u003e\n    \u003cinput type=\"email\" name=\"email\" data-encrypt=\"true\" placeholder=\"Enter your email\" /\u003e\n    \u003cinput type=\"text\" name=\"address\" placeholder=\"Enter your address\" /\u003e\n\n    \u003cdiv class=\"encrypt-form-status\"\u003e\u003c/div\u003e \u003c!-- Optional element to display encryption operation status --\u003e\n\n    \u003cbutton type=\"submit\"\u003eSubmit\u003c/button\u003e\n\u003c/form\u003e\n```\n\n- Add `data-encrypt-form` to the `\u003cform\u003e` tag to enable encryption for this form. All supported form fields will be encrypted.\n    - Use `data-encrypt=\"true\"` for fields that require encryption. All other fields will not be encrypted.\n    - Use `data-encrypt=\"false\"` for fields that do not require encryption. All other fields will be encrypted.\n\n**Types of Fields Available for Encryption:**\n\n- **Input Fields:**\n    - Supported types: `text`, `email`, `password`, `number`, `date`, and similar.\n    - Exceptions: `file`, `checkbox`, `radio`, `select`.\n\n- **Textarea:**\n    - Fully supported.\n\n**!!! It is important to note that the encrypted value will be longer than the original value, which may affect data length constraints.**\n\n### Manual decrypting data on the server\n\nUse the `Decryptor` class to decrypt data on the server:\n\n```php\nuse Bespredel\\EncryptionForm\\Services\\Decryptor;\n\n$decryptor = new Decryptor();\n$value = $request-\u003einput('name'); // Example for 'name' field\n$privateKey = config('encryption-form.private_key');\n$prefix = config('encryption-form.prefix', 'ENCF:');\n\n$decryptedValue = $decryptor-\u003edecryptValue($value, $privateKey, $prefix);\n```\n\nOr use dependency injection:\n\n```php\nuse Bespredel\\EncryptionForm\\Services\\Contracts\\DecryptorInterface;\n\npublic function __construct(DecryptorInterface $decryptor)\n{\n    $this-\u003edecryptor = $decryptor;\n}\n\n// In your method:\n$value = $request-\u003einput('name');\n$privateKey = config('encryption-form.private_key');\n$prefix = config('encryption-form.prefix', 'ENCF:');\n$decryptedValue = $this-\u003edecryptor-\u003edecryptValue($value, $privateKey, $prefix);\n```\n\nOr use the `openssl_private_decrypt` function to decrypt data on the server:\n\n```php\n$privateKey = config('encryption-form.private_key');\n\n$encryptedData = $request-\u003einput('name'); // Example for 'name' field\n$decryptedData = null;\n\n$decodedValue = base64_decode((string)str($encryptedData)-\u003eafter('ENCF:'), true);\nopenssl_private_decrypt($decodedValue, $decryptedData, $privateKey);\n\necho $decryptedData; // Output the decrypted value\n```\n\n---\n\n## ⚡ Commands\n\n### Generate New RSA Keys\n\nTo generate a new pair of RSA keys:\n\n```bash\nphp artisan encryption-form:generate-keys\n```\n\nThis will update the keys in your `.env` file.\nKeys are saved as escaped multiline values to keep the `.env` file parse-safe.\n\n---\n\n## ⚙️ Configuration\n\n### Config File:\n\n```config/encryption-form.php```\n\n```php\nreturn [\n   'public_key'   =\u003e env('ENCRYPTION_FORM_PUBLIC_KEY'), // Public key, required\n   'private_key'  =\u003e env('ENCRYPTION_FORM_PRIVATE_KEY'), // Private key, required\n   'prefix'       =\u003e env('ENCRYPTION_FORM_PREFIX', 'ENCF:'), // Field value prefix, needed for optimization to find encrypted values, default: 'ENCF:'\n   'strict_mode'  =\u003e env('ENCRYPTION_FORM_STRICT_MODE', false), // Throw DecryptionException when encrypted fields fail to decrypt\n   'key_rotation' =\u003e [ // Key automatic rotation configuration\n      'enabled'         =\u003e env('ENCRYPTION_FORM_KEY_ROTATION_ENABLED', false), // Enable key rotation\n      'cron_expression' =\u003e '0 0 * * *', // Cron expression for key rotation\n   ],\n    'skip_for_ips' =\u003e [ // Skip encryption for specific IP addresses\n        //'127.0.0.1',\n    ],\n];\n```\n\n### Quality checks\n\n```bash\ncomposer lint\ncomposer analyse\ncomposer test\n```\n\n### Key Rotation via Scheduler\n\nYou can schedule automatic key rotation via the `key_rotation` key in the config file.:\n\n```php\nreturn [\n    ...\n   'key_rotation' =\u003e [\n     'enabled'         =\u003e env('ENCRYPTION_FORM_KEY_ROTATION_ENABLED', false),\n     'cron_expression' =\u003e '0 0 * * *',\n   ],\n];\n```\n\n---\n\n## 🤝 Contributing\n\n1. Fork the repository.\n2. Create your feature branch: `git checkout -b feature/my-feature`.\n3. Commit your changes: `git commit -m 'Add some feature'`.\n4. Push to the branch: `git push origin feature/my-feature`.\n5. Open a pull request.\n\n---\n\n## 🛡 Security\n\nPLEASE DON'T DISCLOSE SECURITY-RELATED ISSUES PUBLICLY.\n\nIf you discover any security related issues, please email [hello@bespredel.name](hello@bespredel.name) instead of using the issue tracker.\n\n---\n\n## 🙏 Acknowledgements\n\nI would like to thank the authors and contributors of the [JSEncrypt](https://github.com/travist/jsencrypt) library for providing a secure RSA\nencryption solution for client-side data encryption.\n\n---\n\n## 📄 License\n\nThis package is open-source software licensed under the MIT license.\n\n---\n\n## ⭐ Support\n\nIf you find this project useful, give it a star ⭐","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbespredel%2Fencryption-form","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbespredel%2Fencryption-form","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbespredel%2Fencryption-form/lists"}