3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function encrypt_decrypt($action, $string, $secret_key, $secret_iv) { $output = false; if (!extension_loaded('openssl')) { return $string; } $encrypt_method = "AES-256-CBC"; // hash $key = hash('sha256', $secret_key); // iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a warning $iv = substr(hash('sha256', $secret_iv), 0, 16); if($action == 'encrypt') { $output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv); $output = base64_encode($output); } else if($action == 'decrypt'){ $output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv); } return $output; } echo encrypt_decrypt('decrypt', 'NElmZ1VlbnhCOXQ4eVlPelI2YWtQbm9MWlZSeU5jV1VZSFJhY0NHc2dSWT0=', ENCRYPTION_KEY, ENCRYPTION_VI);
based on 9ihf9
Output for 7.2.6
Warning: Use of undefined constant ENCRYPTION_KEY - assumed 'ENCRYPTION_KEY' (this will throw an Error in a future version of PHP) in /in/p0m5m on line 26 Warning: Use of undefined constant ENCRYPTION_VI - assumed 'ENCRYPTION_VI' (this will throw an Error in a future version of PHP) in /in/p0m5m on line 26 NElmZ1VlbnhCOXQ4eVlPelI2YWtQbm9MWlZSeU5jV1VZSFJhY0NHc2dSWT0=
Output for 4.3.0 - 5.4.14, 7.1.20
Notice: Use of undefined constant ENCRYPTION_KEY - assumed 'ENCRYPTION_KEY' in /in/p0m5m on line 26 Notice: Use of undefined constant ENCRYPTION_VI - assumed 'ENCRYPTION_VI' in /in/p0m5m on line 26 NElmZ1VlbnhCOXQ4eVlPelI2YWtQbm9MWlZSeU5jV1VZSFJhY0NHc2dSWT0=
Output for 5.4.15 - 5.6.30, hhvm-3.10.1 - 3.21.3, 7.0.0 - 7.1.10
Notice: Use of undefined constant ENCRYPTION_KEY - assumed 'ENCRYPTION_KEY' in /in/p0m5m on line 26 Notice: Use of undefined constant ENCRYPTION_VI - assumed 'ENCRYPTION_VI' in /in/p0m5m on line 26
Output for hhvm-3.22.0
Notice: Use of undefined constant ENCRYPTION_KEY - assumed 'ENCRYPTION_KEY' in /in/p0m5m on line -1 Notice: Use of undefined constant ENCRYPTION_VI - assumed 'ENCRYPTION_VI' in /in/p0m5m on line -1