browomir/open-encryption

Simple users password encryption class based on OpenSSL

dev-master 2015-11-13 19:20 UTC

This package is not auto-updated.

Last update: 2024-09-14 16:18:56 UTC


README

Simple password encryption class based on OpenSSL.

Prerequisites

  • PHP 5.4 or later

Installation

The preferred way to install this class is through composer.

Either run

php composer.phar require browomir/open-encryption "dev-master"

or add

// composer.json
{
    "require": {
        "browomir/open-encryption": "dev-master"
    }
}

to the require section of your composer.json file.

Usage

This simple example show how you can use this class:

require_once 'vendor/autoload.php';

use OpenEncryption\Encryption;

$username = 'test@example.com';
$password = 'test123';
$salt = 'somesalt';

$encryption = new Encryption(); // you can pass secret key as constructor parameter
                                // e.g. $encryption = new Encryption('mySecret');
$encrypted = $encryption->encrypt($password, $salt, $username);
$decrypted = $encryption->decrypt($encrypted, $salt, $username);

echo 'Encrypted: ' . $encrypted;
echo '<br>';
echo 'Decrypted: ' . $decrypted;

Additional:

  • if you don't want use default cipher method (AES-256-CBC) you can set your own:
$cipher = new Cipher('AES-128-ECB');
$encryption->setCipher($cipher);
  • you can check if chosen cipher is supported and/or is strong:
if ($cipher->isSupported() && $cipher->isCryptoStrong()) {
    echo 'Your cipher is good!';
} else {
    echo 'You should chose other cipher!';
}
  • you can get list of all supported cipher by:
$cipher->getSupportedCiphers();

Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version Latest Unstable Version Dependency Status Total Downloads License