Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mpyw/EasyCrypt
A class that provides simple interface for decryptable encryption.
https://github.com/mpyw/EasyCrypt
encryption php
Last synced: about 2 months 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 (about 11 years ago)
- Default Branch: master
- Last Pushed: 2023-03-13T04:48:35.000Z (over 1 year ago)
- Last Synced: 2024-07-14T23:45:31.855Z (2 months ago)
- Topics: encryption, php
- Language: PHP
- Homepage:
- Size: 60.5 KB
- Stars: 23
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
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) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/mpyw/EasyCrypt/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/mpyw/EasyCrypt/?branch=master)
A class that provides simple interface for **decryptable** encryption.
## Requirements
- PHP: `^7.1 || ^8.0`
## 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