{"id":16675828,"url":"https://github.com/mpyw/easycrypt","last_synced_at":"2025-03-21T18:31:40.800Z","repository":{"id":10325587,"uuid":"12454912","full_name":"mpyw/EasyCrypt","owner":"mpyw","description":"A class that provides simple interface for decryptable encryption.","archived":false,"fork":false,"pushed_at":"2023-03-13T04:48:35.000Z","size":62,"stargazers_count":23,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-13T13:07:48.212Z","etag":null,"topics":["encryption","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/mpyw.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":null}},"created_at":"2013-08-29T08:10:10.000Z","updated_at":"2024-05-09T12:18:06.000Z","dependencies_parsed_at":"2024-01-13T16:25:28.799Z","dependency_job_id":null,"html_url":"https://github.com/mpyw/EasyCrypt","commit_stats":{"total_commits":36,"total_committers":2,"mean_commits":18.0,"dds":0.08333333333333337,"last_synced_commit":"ec32af0092c2566e3267499bf8ee3ef04baeef69"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mpyw%2FEasyCrypt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mpyw%2FEasyCrypt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mpyw%2FEasyCrypt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mpyw%2FEasyCrypt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mpyw","download_url":"https://codeload.github.com/mpyw/EasyCrypt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221817473,"owners_count":16885546,"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":["encryption","php"],"created_at":"2024-10-12T13:08:04.519Z","updated_at":"2025-03-21T18:31:40.784Z","avatar_url":"https://github.com/mpyw.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# EasyCrypt [![Build Status](https://github.com/mpyw/EasyCrypt/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/mpyw/EasyCrypt/actions) [![Coverage Status](https://coveralls.io/repos/github/mpyw/EasyCrypt/badge.svg?branch=master)](https://coveralls.io/github/mpyw/EasyCrypt?branch=master)\n\nA class that provides simple interface for **decryptable** encryption.\n\n## Requirements\n\n- PHP: `^8.2`\n\n\u003e [!NOTE]\n\u003e Older versions have outdated dependency requirements. If you cannot prepare the latest environment, please refer to past releases.\n\n## Installing\n\n```\ncomposer require mpyw/easycrypt\n```\n\n## Usage\n\n### Basic\n\nThe default cipher method is `aes256` (`aes-256-cbc`).\n\n```php\n\u003c?php\n\nuse Mpyw\\EasyCrypt\\Cryptor;\n\n$cryptor = new Cryptor;\n\n$secretData = '[Secret Data]';\n$password = '[Password]';\n\n$encrypted = $cryptor-\u003eencrypt($secretData, $password);\n$decrypted = $cryptor-\u003edecrypt($encrypted, $password); // String on success, false on failure.\n\nvar_dump($secretData === $decrypted); // bool(true)\n```\n\n### Throw `DecryptionFailedException` when decryption failed\n\nIt throws `DecryptionFailedException` instead of returning false.\n\n```php\n$decrypted = $cryptor-\u003emustDecrypt($encrypted, $password);\n```\n\n### Use fixed password\n\nYou can use `FixedPasswordCryptor` instead of raw `Cryptor`.\nThis is useful when we use a fixed password from an application config.\n\n```php\n\u003c?php\n\nuse Mpyw\\EasyCrypt\\FixedPasswordCryptor;\n\n$cryptor = new FixedPasswordCryptor('[Password]');\n\n$secretData = '[Secret Data]';\n\n$encrypted = $cryptor-\u003eencrypt($secretData);\n$decrypted = $cryptor-\u003edecrypt($encrypted); // String on success, false on failure.\n\nvar_dump($secretData === $decrypted); // bool(true)\n```\n\n### Use AEAD (Authenticated Encryption with Associated Data) suites\n\nIf you need to use AEAD suites that adopt CTR mode, it is recommended to provide truly unique counter value.\n\n```php\nuse Mpyw\\EasyCrypt\\IvGenerator\\IvGeneratorInterface;\n\nclass Counter implements IvGeneratorInterface\n{\n    protected \\PDO $pdo;\n\n    public function __construct(\\PDO $pdo)\n    {\n        $this-\u003epdo = $pdo;\n    }\n\n    public function generate(int $length): string\n    {\n        $this-\u003epdo-\u003eexec('INSERT INTO counters()');\n        return $this-\u003epdo-\u003elastInsertId();\n    }\n}\n```\n\n```php\n\u003c?php\n\nuse Mpyw\\EasyCrypt\\Cryptor;\n\n$cryptor = new Cryptor('aes-256-gcm', new Counter(new \\PDO(...)));\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmpyw%2Feasycrypt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmpyw%2Feasycrypt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmpyw%2Feasycrypt/lists"}