Open Encryption
Simple password encryption class based on OpenSSL., (*1)
Prerequisites
Installation
The preferred way to install this class is through composer., (*2)
Either run, (*3)
php composer.phar require browomir/open-encryption "dev-master"
or add, (*4)
// composer.json
{
"require": {
"browomir/open-encryption": "dev-master"
}
}
to the require section of your composer.json
file., (*5)
Usage
This simple example show how you can use this class:, (*6)
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:, (*7)
- 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();
, (*8)