{"id":21486743,"url":"https://github.com/lazervel/cryptor","last_synced_at":"2026-01-04T03:35:12.140Z","repository":{"id":259690797,"uuid":"869168737","full_name":"lazervel/cryptor","owner":"lazervel","description":"Cryptor is a PHP library for easy and secure data encryption and decryption. It supports multiple algorithms.","archived":false,"fork":false,"pushed_at":"2024-11-02T07:13:56.000Z","size":10,"stargazers_count":27,"open_issues_count":0,"forks_count":4,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-01-23T19:41:43.905Z","etag":null,"topics":["cryptor","decrypt","encrypt"],"latest_commit_sha":null,"homepage":"","language":null,"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/lazervel.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,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-07T20:45:57.000Z","updated_at":"2024-12-28T08:18:34.000Z","dependencies_parsed_at":"2024-10-27T11:35:55.825Z","dependency_job_id":"d38aca47-33af-4e4f-a1da-a362b1c9b665","html_url":"https://github.com/lazervel/cryptor","commit_stats":null,"previous_names":["lazervel/cryptor"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lazervel%2Fcryptor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lazervel%2Fcryptor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lazervel%2Fcryptor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lazervel%2Fcryptor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lazervel","download_url":"https://codeload.github.com/lazervel/cryptor/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244014167,"owners_count":20383716,"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":["cryptor","decrypt","encrypt"],"created_at":"2024-11-23T13:23:35.826Z","updated_at":"2026-01-04T03:35:12.133Z","avatar_url":"https://github.com/lazervel.png","language":null,"readme":"# Cryptor\n\nA lightweight and secure PHP encryption library that provides modern **AES-256-GCM** authenticated encryption and decryption with optional AAD (Additional Authenticated Data) support.  \nIt is designed to be **simple, dependency-free**, and compatible with any PHP application or framework.\n\n---\n\n## Features\n\n- ✅ AES-256-GCM authenticated encryption  \n- ✅ Optional AAD (Additional Authenticated Data)  \n- ✅ Secure key handling \u0026 memory cleanup  \n- ✅ JSON + Base64 encoded output  \n- ✅ Key derived safely from `APP_KEY` or custom string  \n- ✅ No framework dependency (works in plain PHP or Laravel)  \n\n---\n\n## Installation\n\nUse Composer (recommended):\n\n```bash\ncomposer require lazervel/cryptor\n```\n\nOr manually include it:\n\n```php\nrequire_once 'src/Cryptor.php';\n```\n\n---\n\n## ⚙️ Environment Setup\n\nSet your application key in `.env` or environment variables:\n\n```env\nAPP_KEY=base64:your-secret-key\n```\n\nAlternatively, you can provide a custom key directly when creating an instance.\n\n---\n\n## 🧠 Basic Usage\n\n```php\n\u003c?php\n\nuse Lazervel\\Cryptor\\Cryptor;\n\n// Create instance (uses APP_KEY from env if not provided)\n$cryptor = new Cryptor('my-secret-key');\n\n// Encrypt a message\n$encrypted = $cryptor-\u003eencrypt('Hello World!');\necho \"Encrypted: \" . $encrypted . PHP_EOL;\n\n// Decrypt the message\n$decrypted = $cryptor-\u003edecrypt($encrypted);\necho \"Decrypted: \" . $decrypted . PHP_EOL;\n\n// Verify that data matches\nif ($cryptor-\u003everify('Hello World!', $encrypted)) {\n    echo \"✅ Data verified successfully!\";\n} else {\n    echo \"❌ Verification failed!\";\n}\n```\n\n---\n\n## 🧩 With Additional Authenticated Data (AAD)\n\nYou can attach additional data (not encrypted but authenticated):\n\n```php\n$add = 'payment#RZP123'; // example reference\n\n$encrypted = $cryptor-\u003eencrypt('Sensitive Transaction Data', 'aes-256-gcm', $add);\n\n// Must use same $add while decrypting\n$decrypted = $cryptor-\u003edecrypt($encrypted, $add);\n```\n\nIf the `$add` differs, decryption will fail — ensuring data integrity.\n\n---\n\n## Security Design\n\n| Aspect | Detail |\n|--------|---------|\n| **Algorithm** | AES-256-GCM (Authenticated Encryption) |\n| **IV** | Generated securely via `random_bytes()` |\n| **Tag** | Auto-generated and verified internally |\n| **Key Derivation** | `hash('sha256', $raw, true)` ensures 32-byte AES key |\n| **Memory Safety** | Key wiped in destructor (`__destruct()`) |\n| **Serialization Protection** | `__sleep()` prevents exposing secrets |\n| **Debug Protection** | `__debugInfo()` hides the key during dumps |\n\n---\n\n## Error Handling\n\n| Error | Thrown when |\n|-------|--------------|\n| `RuntimeException` | No key found in environment |\n| `InvalidArgumentException` | Unsupported cipher name |\n| `false` return | Encryption/decryption failure |\n\nYou can wrap encryption/decryption calls inside `try/catch` if desired:\n\n```php\ntry {\n    $cryptor = new Cryptor();\n    $data = $cryptor-\u003edecrypt($input);\n} catch (RuntimeException $e) {\n    echo $e-\u003egetMessage();\n}\n```\n\n---\n\n## 🧰 Supported Ciphers\n\n| Cipher | Description |\n|---------|--------------|\n| `aes-256-gcm` | (Default) Modern authenticated encryption |\n| `aes-128-gcm` | Lightweight variant |\n| `aes-256-cbc` | Legacy compatibility mode (no authentication) |\n\n\u003e GCM mode is recommended for all new applications.\n\n---\n\n## Example Output Format\n\nEncrypted data is a **Base64-encoded JSON** like this:\n\n```json\n{\n  \"iv\": \"r7KfWkJcGlZcL7hYp6oJrQ==\",\n  \"value\": \"J9PDpax7oMGJ6M4qYQ==\",\n  \"cipher\": \"YWVzLTI1Ni1nY20=\",\n  \"tag\": \"AQIDBAUGBwgJCgsMDQ==\"\n}\n```\n\nEntire JSON is Base64 encoded again to make it safe for database or URL storage.\n\n---\n\n## Methods Summary\n\n| Method | Description |\n|--------|--------------|\n| `__construct(?string $key = null)` | Initialize with custom or env key |\n| `encrypt(string $data, ?string $cipher = null, string $add = '')` | Encrypt data |\n| `decrypt(string $data, string $add = '')` | Decrypt data |\n| `verify(string $plain, string $encrypted, string $add = '')` | Check if decrypted value matches plain text |\n\n---\n\n## Example Integration (with Laravel)\n\n```php\n// config/app.php\n'providers' =\u003e [\n    Lazervel\\Cryptor\\Cryptor::class,\n],\n\n// usage\n$cryptor = app(Lazervel\\Cryptor\\Cryptor::class);\n$encrypted = $cryptor-\u003eencrypt('Secret Message');\n```\n\n---\n\n## License\n\nThis package is open-sourced software licensed under the **MIT License**.\n\n---\n\n## Author\n\n**Indian Modassir**  \nDeveloper of [Lazervel](https://github.com/indianmodassir) — a collection of modern PHP libraries for secure, modular development.\n\n---\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flazervel%2Fcryptor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flazervel%2Fcryptor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flazervel%2Fcryptor/lists"}