https://github.com/mpyw/EasyCrypt
A class that provides simple interface for decryptable encryption.
https://github.com/mpyw/EasyCrypt
encryption php
Last synced: 7 days ago
JSON representation
A class that provides simple interface for decryptable encryption.
- Host: GitHub
- URL: https://github.com/mpyw/EasyCrypt
- Owner: mpyw
- License: mit
- Created: 2013-08-29T08:10:10.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2025-03-04T06:52:55.000Z (4 months ago)
- Last Synced: 2025-07-07T05:43:57.999Z (9 days ago)
- Topics: encryption, php
- Language: PHP
- Homepage:
- Size: 54.7 KB
- Stars: 23
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# EasyCrypt [](https://github.com/mpyw/EasyCrypt/actions) [](https://coveralls.io/github/mpyw/EasyCrypt?branch=master)
A class that provides simple interface for **decryptable** encryption.
## Requirements
- PHP: `^8.2`
> [!NOTE]
> Older versions have outdated dependency requirements. If you cannot prepare the latest environment, please refer to past releases.## Installing
```
composer require mpyw/easycrypt
```## Usage
### Basic
The default cipher method is `aes256` (`aes-256-cbc`).
```php
encrypt($secretData, $password);
$decrypted = $cryptor->decrypt($encrypted, $password); // String on success, false on failure.var_dump($secretData === $decrypted); // bool(true)
```### Throw `DecryptionFailedException` when decryption failed
It throws `DecryptionFailedException` instead of returning false.
```php
$decrypted = $cryptor->mustDecrypt($encrypted, $password);
```### Use fixed password
You can use `FixedPasswordCryptor` instead of raw `Cryptor`.
This is useful when we use a fixed password from an application config.```php
encrypt($secretData);
$decrypted = $cryptor->decrypt($encrypted); // String on success, false on failure.var_dump($secretData === $decrypted); // bool(true)
```### Use AEAD (Authenticated Encryption with Associated Data) suites
If you need to use AEAD suites that adopt CTR mode, it is recommended to provide truly unique counter value.
```php
use Mpyw\EasyCrypt\IvGenerator\IvGeneratorInterface;class Counter implements IvGeneratorInterface
{
protected \PDO $pdo;public function __construct(\PDO $pdo)
{
$this->pdo = $pdo;
}public function generate(int $length): string
{
$this->pdo->exec('INSERT INTO counters()');
return $this->pdo->lastInsertId();
}
}
``````php