2017 © Pedro Peláez
 

library easycrypt

A class that provides simple interface for decryptable encryption.

image

mpyw/easycrypt

A class that provides simple interface for decryptable encryption.

  • Tuesday, August 30, 2016
  • by mpyw
  • Repository
  • 2 Watchers
  • 18 Stars
  • 45 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 2 Versions
  • 5 % Grown

The README.md

EasyCrypt Build Status Coverage Status

A class that provides simple interface for decryptable encryption., (*1)

Requirements

  • PHP: ^8.2

[!NOTE] Older versions have outdated dependency requirements. If you cannot prepare the latest environment, please refer to past releases., (*2)

Installing

composer require mpyw/easycrypt

Usage

Basic

The default cipher method is aes256 (aes-256-cbc)., (*3)

<?php

use Mpyw\EasyCrypt\Cryptor;

$cryptor = new Cryptor;

$secretData = '[Secret Data]';
$password = '[Password]';

$encrypted = $cryptor->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., (*4)

$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., (*5)

<?php

use Mpyw\EasyCrypt\FixedPasswordCryptor;

$cryptor = new FixedPasswordCryptor('[Password]');

$secretData = '[Secret Data]';

$encrypted = $cryptor->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., (*6)

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

use Mpyw\EasyCrypt\Cryptor;

$cryptor = new Cryptor('aes-256-gcm', new Counter(new \PDO(...)));

The Versions

30/08 2016

dev-master

9999999-dev

A class that provides simple interface for decryptable encryption.

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • ext-openssl *

 

The Development Requires

encrypt decrypt openssl

09/08 2016

v3.0.0

3.0.0.0

A class that provides simple interface for decryptable encryption.

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • ext-openssl *

 

The Development Requires

encrypt decrypt openssl