Perform AES-256 (CBC) encryption/decryption compatible with OpenSSL, CryptoJS, Gibberish AES and possibly other libraries.
Can be used to encrypt data in PHP and decrypt in JavaScript, or vice versa.
Code from here: http://uk3.php.net/manual/en/function.openssl-decrypt.php#107210
- PHP 5.3.3 or later
- OpenSSL extension for PHP
In composer.json
:
{
"require": {
"legierski/aes": "0.1.*"
}
}
$aes = new \Legierski\AES\AES;
$encrypted = $aes->encrypt('Very sensitive data', 'password');
// OpenSSL will truncate rows longer than 76 characters, so let's wrap our encrypted data
$encryptedForOpenSSL = $aes->wrapForOpenSSL($encrypted);
$aes = new \Legierski\AES\AES;
$decrypted = $aes->decrypt('U2FsdGVkX1+nnmEfHgoGQpwSPcT+mDZHxhr8XhEsmIvT2JAxsIzsRocO6x1PErrF', 'password');
$ echo "Very sensitive data" | openssl enc -aes-256-cbc -a -k password
$ echo "U2FsdGVkX1+nnmEfHgoGQpwSPcT+mDZHxhr8XhEsmIvT2JAxsIzsRocO6x1PErrF" | openssl enc -aes-256-cbc -a -d -k password
var encrypted = CryptoJS.AES.encrypt('Very sensitive data', 'password').toString();
var decrypted = CryptoJS.AES.decrypt('U2FsdGVkX1+nnmEfHgoGQpwSPcT+mDZHxhr8XhEsmIvT2JAxsIzsRocO6x1PErrF', 'password').toString(CryptoJS.enc.Utf8);
var encrypted = GibberishAES.enc('Very sensitive data', 'password');
var decrypted = GibberishAES.dec('U2FsdGVkX1+nnmEfHgoGQpwSPcT+mDZHxhr8XhEsmIvT2JAxsIzsRocO6x1PErrF', 'password');
Run unit tests:
$ ./vendor/bin/phpunit
Test compliance with PSR2 coding style guide:
$ ./vendor/bin/phpcs --standard=PSR2 ./src
The MIT License (MIT)