<?PHP
$data = "JlTf/Y6JTO6dXUbYrEcCuQ==";
$key = "Salted_key_is_here";
$test = decrypt256($data, $key);
echo "Result: " . $test;
function encrypt256($data, $key)
{
$method = 'aes-256-cbc';
// Must be exact 32 chars (256 bit). Salt32 make a robust hash around the entered key
$password = $key; //salt32($key);
// IV must be exact 16 chars (128 bit) Example with zeros
$iv = chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0);
//
$encrypted = base64_encode(openssl_encrypt($data, $method, $password, OPENSSL_RAW_DATA, $iv));
return $encrypted;
}
function decrypt256($dataEncrypted, $key)
{
$method = 'aes-256-cbc';
// Must be exact 32 chars (256 bit). Salt32 make a robust hash around the entered key
$password = $key; //salt32($key);
// IV must be exact 16 chars (128 bit) Example with zeros
$iv = chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0);
//
$decrypted = openssl_decrypt(base64_decode($dataEncrypted), $method, $password, OPENSSL_RAW_DATA, $iv);
return $decrypted;
}
?>