{"id":13405186,"url":"https://github.com/miladrahimi/phpcrypt","last_synced_at":"2026-01-11T16:38:54.468Z","repository":{"id":33898295,"uuid":"37612733","full_name":"miladrahimi/phpcrypt","owner":"miladrahimi","description":"Encryption, decryption, and password hashing tools for PHP projects","archived":false,"fork":false,"pushed_at":"2020-10-17T12:54:38.000Z","size":90,"stargazers_count":30,"open_issues_count":0,"forks_count":6,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-20T10:12:01.928Z","etag":null,"topics":["aes","asymmetric","cryptography","decrypt","encrypt","hash","openssl","rsa","symmetric"],"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/miladrahimi.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":"2015-06-17T18:20:39.000Z","updated_at":"2024-09-13T06:56:59.000Z","dependencies_parsed_at":"2022-08-17T20:15:34.310Z","dependency_job_id":null,"html_url":"https://github.com/miladrahimi/phpcrypt","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miladrahimi%2Fphpcrypt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miladrahimi%2Fphpcrypt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miladrahimi%2Fphpcrypt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miladrahimi%2Fphpcrypt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/miladrahimi","download_url":"https://codeload.github.com/miladrahimi/phpcrypt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243554266,"owners_count":20309901,"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":["aes","asymmetric","cryptography","decrypt","encrypt","hash","openssl","rsa","symmetric"],"created_at":"2024-07-30T19:01:57.078Z","updated_at":"2026-01-11T16:38:54.420Z","avatar_url":"https://github.com/miladrahimi.png","language":"PHP","readme":"[![Latest Stable Version](https://poser.pugx.org/miladrahimi/phpcrypt/v/stable)](https://packagist.org/packages/miladrahimi/phpcrypt)\n[![Total Downloads](https://poser.pugx.org/miladrahimi/phpcrypt/downloads)](https://packagist.org/packages/miladrahimi/phpcrypt)\n[![Build Status](https://travis-ci.org/miladrahimi/phpcrypt.svg?branch=master)](https://travis-ci.org/miladrahimi/phpcrypt)\n[![Coverage Status](https://coveralls.io/repos/github/miladrahimi/phpcrypt/badge.svg?branch=master)](https://coveralls.io/github/miladrahimi/phpcrypt?branch=master)\n[![License](https://poser.pugx.org/miladrahimi/phpcrypt/license)](https://packagist.org/packages/miladrahimi/phpcrypt)\n\n# PhpCrypt\n\nPhpCrypt is a package for encryption, decryption, and hashing data in PHP projects.\nIt provides an easy-to-use and fluent interface.\n\nFeatures:\n* Symmetric encryption/decryption using AES and other symmetric methods.\n* Asymmetric encryption/decryption using the RSA method.\n* Hashing and verifying data (e.g. passwords) using the BCrypt method.\n\n## Versions\n\n* v5.x.x\n* v4.x.x\n* v3.x.x (Unsupported)\n* v2.x.x (Unsupported)\n* v1.x.x (Unsupported)\n\n## Installation\n\nInstall [Composer](https://getcomposer.org) and run the following command in your project's root directory:\n\n```bash\ncomposer require miladrahimi/phpcrypt \"5.*\"\n```\n\n## Symmetric Encryption\n\nThis example shows how to encrypt and decrypt data using symmetric algorithms like AES.\n\n```php\nuse MiladRahimi\\PhpCrypt\\Symmetric;\n\n$symmetric = new Symmetric();\n$encryptedData = $symmetric-\u003eencrypt('secret');\necho $symmetric-\u003edecrypt($encryptedData); // secret\n```\n\nIt generates a random key and uses `aes-256-cbc` method for encrypting/decrypting data.\n\n### Custom Key\n\nIf you have already a key, you can use your own key like this:\n\n```php\nuse MiladRahimi\\PhpCrypt\\Symmetric;\n\n$key = '1234567890123456';\n\n// Set the key using the constructor\n$symmetric = new Symmetric($key);\n\n// Or set the key using the setter\n$symmetric = new Symmetric();\n$symmetric-\u003esetKey($key);\n\n// And get the key using the getter\n$myKey = $symmetric-\u003egetKey();\n```\n\nThe method `generateKey` can help you to generate a new random key.\nSee the snippet below.\n\n```php\nuse MiladRahimi\\PhpCrypt\\Symmetric;\n\n$key = Symmetric::generateKey();\n```\n\n### Custom Methods\n\nIn default, The `Symmetric` class uses `aes-256-cbc` method to encrypt/decrypt data.\nYou can use your preferred method as well.\nSee the following example.\n\n```php\nuse MiladRahimi\\PhpCrypt\\Exceptions\\MethodNotSupportedException;\nuse MiladRahimi\\PhpCrypt\\Symmetric;\n\ntry {\n    $symmetric = new Symmetric();\n    $symmetric-\u003esetMethod('aria-256-ctr');\n    // ...\n} catch (MethodNotSupportedException $e) {\n    // The method is not supported.\n}\n```\n\n### Supported Methods\n\nIf you want to know which methods do your installed OpenSSL extension support, see the snippet below:\n\n```php\nuse MiladRahimi\\PhpCrypt\\Symmetric;\n\nprint_r(Symmetric::supportedMethods());\n```\n\n## RSA Encryption\n\nRSA is a popular asymmetric encryption/decryption algorithm.\nThe examples below illustrate how to encrypt/decrypt data using the RSA algorithm.\n\n### Encryption with private key\n\nIn this example, we encrypt data with a private key and decrypt it with the related public key.\n\n```php\nuse MiladRahimi\\PhpCrypt\\PrivateRsa;\nuse MiladRahimi\\PhpCrypt\\PublicRsa;\n\n$privateRsa = new PrivateRsa('private_key.pem');\n$publicRsa = new PublicRsa('public_key.pem');\n\n$result = $privateRsa-\u003eencrypt('secret');\necho $publicRsa-\u003edecrypt($result); // secret\n```\n\n### Encryption with public key\n\nIn this example, we encrypt data with a public key and decrypt it with the related private key.\n\n```php\nuse MiladRahimi\\PhpCrypt\\PrivateRsa;\nuse MiladRahimi\\PhpCrypt\\PublicRsa;\n\n$privateRsa = new PrivateRsa('private_key.pem');\n$publicRsa = new PublicRsa('public_key.pem');\n\n$result = $publicRsa-\u003eencrypt('secret');\necho $privateRsa-\u003edecrypt($result); // secret\n```\n\n### Base64 Encoding\n\nIn default, the encrypted data returned by `PrivateRsa::encrypt()` and `PublicRsa::encrypt()` methods will be Base64 encoded.\nYou can disable this encoding like the example below.\n\n```php\nuse MiladRahimi\\PhpCrypt\\PrivateRsa;\nuse MiladRahimi\\PhpCrypt\\PublicRsa;\n\n$privateRsa = new PrivateRsa('private_key.pem');\n$publicRsa = new PublicRsa('public_key.pem');\n\n// Disable Base64 encoding for public encryption\n$result = $publicRsa-\u003eencrypt('secret', false);\n\n// Disable Base64 encoding for private encryption\n$result = $privateRsa-\u003eencrypt('secret', false);\n```\n\n## Hashing\n\nThis example shows how to hash data and verify it.\n\n```php\nuse MiladRahimi\\PhpCrypt\\Hash;\n\n$hash = new Hash();\n\n$hashedPassword = $hash-\u003emake('MyPassword');\necho $hash-\u003everify('MyPassword', $hashedPassword); // true\necho $hash-\u003everify('AnotherPassword', $hashedPassword); // false\n```\n\n## Error Handling\n\nThe `Symmetric`, `PrivateRsa`, `PublicRsa`, and `Hash` classes may throw these exceptions:\n\n* `EncryptionException`: When it cannot encrypt data.\n* `DecryptionException`: When it cannot decrypt data.\n* `HashingException`: When it cannot hash data.\n* `MethodNotSupportedException`: When the passed encryption method to the `Symmetric` class is not supported.\n* `InvalidKeyException`: When the passed key to `PrivateRsa` or `PublicRsa` classes is not valid.\n\n## License\n\nPhpCrypt is initially created by [Milad Rahimi](https://miladrahimi.com) and released under the [MIT License](http://opensource.org/licenses/mit-license.php).\n","funding_links":[],"categories":["PHP"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiladrahimi%2Fphpcrypt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmiladrahimi%2Fphpcrypt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiladrahimi%2Fphpcrypt/lists"}