composer require mokhovevgeniigennadevich/php-cryptojs-encrypt-decrypt
<?php
include('vendor/autoload.php');
use CryptoJSPHP\CryptoJSPHP;
// Generate Keys
echo '<p><b>Generating Keys</b></p>';
$CryptoJSPHP = new CryptoJSPHP('', '', 'aes-256-cbc', 'sha256');
$OpenSSLKey = $CryptoJSPHP->getOpenSSLKey();
$HashKey = $CryptoJSPHP->getHashKey();
echo '<p>OpenSSLKey: '.$OpenSSLKey.'</p>';
echo '<p>HashKey: '.$HashKey.'</p>';
// aes-256-cbc and sha256 test
$CryptoJSPHP = new CryptoJSPHP($OpenSSLKey, $HashKey, 'aes-256-cbc', 'sha256');
$data = 'Hello World! This is secret string...';
$encrypted = $CryptoJSPHP->encrypt($data);
$decrypted = $CryptoJSPHP->decrypt($encrypted);
echo '<p><b>Testing aes-256-cbc and sha256</b></p>';
echo '<p>OpenSSLKey: '.$OpenSSLKey.'</p>';
echo '<p>HashKey: '.$HashKey.'</p>';
echo '<p>String: '.$data.'</p>';
echo '<p>Encrypted: '.$encrypted.'</p>';
echo '<p>Decrypted: '.$decrypted.'</p>';
// Generate Keys
echo '<p><b>Generating Keys</b></p>';
$CryptoJSPHP = new CryptoJSPHP('', '', 'aes-256-cbc', 'sha512');
$OpenSSLKey = $CryptoJSPHP->getOpenSSLKey();
$HashKey = $CryptoJSPHP->getHashKey();
echo '<p>OpenSSLKey: '.$OpenSSLKey.'</p>';
echo '<p>HashKey: '.$HashKey.'</p>';
// aes-256-cbc and sha512
$CryptoJSPHP = new CryptoJSPHP($OpenSSLKey, $HashKey, 'aes-256-cbc', 'sha512');
$data = 'This is second <b>Very</b> secured string we want to encrypt...';
$encrypted = $CryptoJSPHP->encrypt($data);
$decrypted = $CryptoJSPHP->decrypt($encrypted);
echo '<p><b>Testing aes-256-cbc and sha512</b></p>';
echo '<p>OpenSSLKey: '.$OpenSSLKey.'</p>';
echo '<p>HashKey: '.$HashKey.'</p>';
echo '<p>String: '.$data.'</p>';
echo '<p>Encrypted: '.$encrypted.'</p>';
echo '<p>Decrypted: '.$decrypted.'</p>';